2016"百(sha)度(bi)之星"-资格赛(Astar Round 1)题解
来源:互联网 发布:ping命令使用的端口 编辑:程序博客网 时间:2024/06/04 21:05
昨天中午一年一坑人的百(sha)度(bi)之星又开赛了,当然正赛的话是下周开始,最先开始的是资格赛。资格赛嘛,过一题就算过了,所以也不管那么多了,就在比赛结束前把题解贴出来了。然后呢,果然不愧是刚刚被政府找去谈话的百度,秉承着坑死你们这帮acmer的精神,资格赛的数据基本是闭着眼睛出的(全TM是非法数据)。但是这并不妨碍我们做做这些题目(反正已经有前辈把非法数据测出来了),我们还是可以ak它的。
Problem A
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1001
分析:第一道题呢就非常非常的坑。简单点来说,就是给你一些数据(char其实就是int嘛),让你求特定区间所有数据-28后的乘积(对于不知道π那个记号表示累乘的,怜悯你们一分钟)。那么很显然的想到肯定是把前n个数据-28后的乘积打表嘛,然后对于给定区间,只需要把dat[b]/dat[a-1]就可以了吗,因为要取模嘛,所以可能不一定可以整除,所以用逆元来将除转换成乘,是一道比较简单的题。
然后,我开开心心的写完了,交了,WA了,醉了。然后我不信邪,多次修改,WA了七八次,崩溃了,怎么都想不到为什么会错。大约一个小时后,我听说是有非法数据,我疯了,就想找到出题人,把他揍一顿。然后再找到验题组,把他们也揍一顿。
然后就是,打表的需要将第一个留出来存1,这样非法数据输出就和标程一样了,呵呵。
#include <map>#include <set>#include <stack>#include <cmath>#include <queue>#include <bitset>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <fstream>#include <cstdlib>#include <sstream>#include <cstring>#include <iostream>#include <algorithm>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define clr(x,y) memset(x,y,sizeof(x))#define rep(i,n) for(int i=0;i<(n);i++)#define repf(i,a,b) for(int i=(a);i<=(b);i++)#define maxn 100000+5#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define IT iterator#define PB push_back#define Times 10typedef long long ll;typedef unsigned long long ull;const double eps = 1e-10;const double pi = acos(-1);const ll mod = 1e9+7; const int inf = 0x3f3f3f3f;const ll M = 9973;char s[maxn];ll dat[maxn];ll qlow(ll a,ll n,ll p){ ll ans=1; while(n) { if(n&1)ans=(ans*a)%p; a=a*a%p; n>>=1; } return ans;}int main(){ //freopen("d:\\acm\\in.in","r",stdin); int n; while(~scanf("%d",&n)) { scanf("%s",s); int len=strlen(s); dat[0]=1; for(int i=1;i<=len;i++) dat[i]=dat[i-1]*(s[i-1]-28)%M; while(n--) { ll a,b; scanf("%I64d %I64d",&a,&b); cout<<dat[b]*qlow(dat[a-1],M-2,M)%M<<endl; } } return 0;}
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1002
分析:这是一道组合数学结论题。为什么说是结论题呢,因为答案就是斐波那契数列,你问为什么我会知道?废话我死算打表看出来的呗。我一开始不知道,但是看出对于有n个1的情况,答案是C(0,n)+C(1,n-1)+C(2,n-2)+。。。,一直加到C上面的数小于等于下面的数。然后,然后我竟然没有搜oeis.org,就自己开始模拟死算,首先佩服我的毅力一分钟,然后鄙视我一小时。反正最后答案是斐波那契,我暴力打表的代码就不贴了。
哦,对了,因为到200,所以数据过大,需要高精度。然后这里面有非法数据,对于n==1的情况,请输出一个空行,否则就是错的。=、=
Problem C
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1003
分析:听他们说是什么Trie,然后我就回去学了一发Trie(没办法,什么都不会),本来不想写的,但是发现题目真TM简单,学完回来就赶紧写了一发。
写法上有点弱把,删除没有好好写,感觉没有必要写得那么好。
就是对于每个构成字符串的结点标记下(插入),搜索的话对于前缀后面的所有子节点都遍历一下看看有没有字符串标记(查询),删除的话直接将前缀后面的所有子节点删掉就可以了(删除)。
#include <map>#include <set>#include <stack>#include <cmath>#include <queue>#include <bitset>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <fstream>#include <cstdlib>#include <sstream>#include <cstring>#include <iostream>#include <algorithm>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define clr(x,y) memset(x,y,sizeof(x))#define rep(i,n) for(int i=0;i<(n);i++)#define repf(i,a,b) for(int i=(a);i<=(b);i++)#define maxn 500000+10#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define IT iterator#define PB push_back#define Times 10typedef long long ll;typedef unsigned long long ull;const double eps = 1e-10;const double pi = acos(-1);const ll mod = 1e9+7; const int inf = 0x3f3f3f3f;struct Trie{ bool isword; Trie* next[26];}root;void insert(char* str){ Trie* p=&root; while(*str) { int id=*str-'a'; if(!p->next[id]) p->next[id]=new Trie(); p=p->next[id]; str++; } p->isword=true;}bool searchall(Trie* p){ if(p->isword)return true; for(int i=0;i<26;i++) if(p->next[i]&&searchall(p->next[i])) return true; return false;}bool search(char* str){ Trie* p=&root; while(*str) { int id=*str-'a'; if(!p->next[id])return false; p=p->next[id]; str++; } return searchall(p);}void deleteall(Trie* p){ for(int i=0;i<26;i++) if(p->next[i]) deleteall(p->next[i]); delete p;}void dele(char* str){ Trie *p=&root,*pre=&root; while(*str) { int id=*str-'a'; if(!p->next[id])return; pre=p; p=p->next[id]; str++; } str--; deleteall(p); pre->next[*str-'a']=NULL;}char dat[35];int main(){ //freopen("d:\\acm\\in.in","r",stdin); int n; scanf("%d",&n); while(n--) { string t; cin>>t; scanf("%s",dat); if(t=="insert")insert(dat); else if(t=="search") { if(search(dat))puts("Yes"); else puts("No"); } else dele(dat); } return 0;}
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1004
分析:没啥好说的把,每个string排下序,然后map,你懂的。
#include <map>#include <set>#include <stack>#include <cmath>#include <queue>#include <bitset>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <fstream>#include <cstdlib>#include <sstream>#include <cstring>#include <iostream>#include <algorithm>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define clr(x,y) memset(x,y,sizeof(x))#define rep(i,n) for(int i=0;i<(n);i++)#define repf(i,a,b) for(int i=(a);i<=(b);i++)#define maxn 1000000+10#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define IT iterator#define PB push_back#define Times 10typedef long long ll;typedef unsigned long long ull;const double eps = 1e-10;const double pi = acos(-1);const ll mod = 1e9+7; const int inf = 0x3f3f3f3f;map<string,int>mapp;int main(){ //freopen("d:\\acm\\in.in","r",stdin); int n; scanf("%d",&n); while(n--) { string t; cin>>t; sort(t.begin(),t.end()); cout<<mapp[t]++<<endl; } return 0;}
http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=690&pid=1005
分析:没啥好分析的把,模拟水题。看懂题意,看懂样例,然后就可以水了。
#include <map>#include <set>#include <stack>#include <cmath>#include <queue>#include <bitset>#include <string>#include <vector>#include <cstdio>#include <cctype>#include <fstream>#include <cstdlib>#include <sstream>#include <cstring>#include <iostream>#include <algorithm>#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;#define clr(x,y) memset(x,y,sizeof(x))#define rep(i,n) for(int i=0;i<(n);i++)#define repf(i,a,b) for(int i=(a);i<=(b);i++)#define maxn 1000+10#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define IT iterator#define PB push_back#define Times 10typedef long long ll;typedef unsigned long long ull;const double eps = 1e-10;const double pi = acos(-1);const ll mod = 1e9+7; const int inf = 0x3f3f3f3f;struct poi{ bool vis; int maxx; int minn;}dat[maxn][35];int num=0;map<string,int>mapp;bool flag[maxn];bool ju(int a,int b,int c,int d){ if(a>d||b<c)return false; else return true;}int main(){ //freopen("d:\\acm\\in.in","r",stdin); int n; scanf("%d",&n); string a; cin>>a; for(int i=1;i<=n;i++) { do { if(a==",")cin>>a; if(mapp.find(a)==mapp.end()) mapp[a]=num++; int X=mapp[a]; int shu; cin>>a>>shu; if(a=="<"||a=="<=") { if(a=="<")shu--; if(dat[i][X].vis) { if(shu>=dat[i][X].minn&&shu<=dat[i][X].maxx)dat[i][X].maxx=shu; else if(shu<dat[i][X].minn)flag[i]=true; } else { dat[i][X].vis=true; dat[i][X].minn=-20000; dat[i][X].maxx=shu; } } else if(a==">"||a==">=") { if(a==">")shu++; if(dat[i][X].vis) { if(shu>=dat[i][X].minn&&shu<=dat[i][X].maxx)dat[i][X].minn=shu; else if(shu>dat[i][X].maxx)flag[i]=true; } else { dat[i][X].vis=true; dat[i][X].minn=shu; dat[i][X].maxx=20000; } } else { if(dat[i][X].vis) { if(shu>=dat[i][X].minn&&shu<=dat[i][X].maxx)dat[i][X].minn=dat[i][X].maxx=shu; else flag[i]=true; } else { dat[i][X].vis=true; dat[i][X].minn=shu; dat[i][X].maxx=shu; } } cin>>a; }while(a==","); if(flag[i]) { puts("unique"); continue; } int ans=1; int ant=0; for(int j=1;j<i;j++) { if(flag[j])continue; for(int k=0;k<num;k++) if(dat[i][k].vis&&dat[j][k].vis) { if(ju(dat[i][k].minn,dat[i][k].maxx,dat[j][k].minn,dat[j][k].maxx)) { ans=0; if(ant)cout<<" "<<j; else cout<<j; ant=1; break; } } else if(dat[i][k].vis||dat[j][k].vis) { ans=0; if(ant)cout<<" "<<j; else cout<<j; ant=1; break; } } if(ans)puts("unique"); else puts(""); } return 0;}
总结:其实也没什么好总结的,总体来说比上次资格赛难了那么一点点。其实真正难的地方是非法数据 =。=
- 2016"百(sha)度(bi)之星"-资格赛(Astar Round 1)题解
- 2016"百度之星" - 资格赛(Astar Round1) 题解
- 2016"百度之星" - 资格赛(Astar Round1)
- 2016"百度之星" - 资格赛(Astar Round1) C
- 2016"百度之星" - 资格赛(Astar Round1)Problem B
- 2016"百度之星" - 资格赛(Astar Round1) Problem D
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- 2016"百度之星" - 资格赛(Astar Round1) Problem D
- 2016"百度之星" - 资格赛(Astar Round1)
- 2016"百度之星" - 资格赛(Astar Round1)Problem D
- 2016"百度之星" - 资格赛(Astar Round1)Problem A
- 2016"百度之星" - 资格赛(Astar Round1)Problem B
- 2016"百度之星" - 资格赛(Astar Round1)Problem C
- 2016"百度之星" - 资格赛(Astar Round1)Problem D
- 2016"百度之星" - 资格赛(Astar Round1)【解题报告】
- 2016"百度之星" - 资格赛(Astar Round1)
- Problem B 2016"百度之星" - 资格赛(Astar Round1)
- Problem D 2016"百度之星" - 资格赛(Astar Round1)
- IMF SparkStreaming 自定义EventLoop 从入门到放弃
- 2016"百度之星" - 资格赛 Problem C
- ORA-12514 startup mount时遇到ORA-12514
- 周赛题(2016"百度之星" - 资格赛(Astar Round1))
- 通过CIFilter生成二维码
- 2016"百(sha)度(bi)之星"-资格赛(Astar Round 1)题解
- 如何下载Instagram照片/视频到手机
- php以图搜图
- iOS 打包问题汇总
- mysql connector c++ {realStr=<读取字符串的字符时出错。> }
- 用MATLAB求多个集合的交集
- ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法 listener.ora修改
- php读取数据库信息的几种方法
- cocos2d-x windows环境下配置