好吧!已经第三场了,依然只会刷出水题,在不突破,就Game over了!
overview http://acm.hust.edu.cn/vjudge/contest/view.action?cid=20428#overview
在球场打球,居然忘了时间,打到了17:57,还有三分钟买了瓶水奔到502,囧。。。
一看人都齐了,其实真是有点怕怕的,一点小紧张!
打开电脑,看到了A题,呵呵应该是学长给的签到题,只是两个循环的变量i,j;我都写成了i,得出一个负数,郁闷+紧张+调试,22min后,AC,显然稳稳成为当时的最后一名。
然后迅速,向后看了两三题,锁定到了E题水的,只是一个二次排序,然后顺利秒掉,之后好像跑到第8了吧!
好了,菜鸟后面就各种悲催了!先是看到F题有人干掉,果断转向F题,但是好像我没有思路。
然后看到C题有那么多的人提交但是只有一人做出,我也想去试一试,题意倒是读懂了,可是具体怎么做,真的不确定,用并查集试了一下,WA!,后来借来纸和笔分析了下,妙思较复杂,先搁置了一边。
这时来到了B题,可能这次唯一留有遗憾的就是B题吧!这时剩的时间还有50min左右,题好长,读了大致,写出了代码,调试了修改了几次,弄出了样例的结果,交上WA,这时只剩2分钟了,不知不觉中结束了!
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
Problem B Persistent Bits problem link adress:http://poj.org/problem?id=3652
For this problem, I think the reason I failed was I ignored one detial, that's :"Note that a sequence does not need to return to the seed: with A = 2,
B = 0, C = 16, and S = 2, the sequence goes 2, 4, 8, 0, 0, 0, ...."
the code I submited yesterday is:
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 int num[65537][33]; 6 int a,b,c,s; 7 int k; 8 int f; 9 void handle(int x) 10 { 11 int w; 12 w=x; 13 int m=31; 14 while(w!=0) 15 { 16 num[k][m--]=w%2; 17 w/=2; 18 } 19 20 k++; 21 } 22 23 24 int main() 25 { 26 while(scanf("%d",&a)&&a) 27 { 28 int i,j; 29 scanf("%d%d%d",&b,&c,&s); 30 memset(num,0,sizeof(num)); 31 k=0; 32 int t=s; 33 handle(s); 34 35 for(i=1;i<=65537;i++) 36 { 37 int temp=(a*t+b)%c; 38 if(temp==s) break; 39 handle(temp);t=temp; 40 } 41 42 43 char ans[17]; 44 int on,z; 45 46 for(i=16;i<=31;i++) 47 { on=0;z=0; 48 for(j=0;j<k;j++) 49 { 50 if(num[j][i]==0) 51 z++; 52 else 53 on++; 54 } 55 if(z==k) ans[i-16]='0'; 56 else if(on==k) ans[i-16]='1'; 57 else ans[i-16]='?'; 58 } 59 ans[16]='\0'; 60 puts(ans); 61 } 62 return 0; 63 }
after settled the mentioned detail above,the problem was accepted!
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 int num[65537][33]; 6 int visit[65537]; 7 int a,b,c,s; 8 int k; 9 int f; 10 void handle(int x) 11 { 12 int w; 13 w=x; 14 int m=15; 15 while(w!=0) 16 { 17 num[k][m--]=w%2; 18 w/=2; 19 } 20 21 k++; 22 } 23 24 25 int main() 26 { 27 while(scanf("%d",&a)&&a) 28 { 29 int i,j; 30 scanf("%d%d%d",&b,&c,&s); 31 memset(visit,0,sizeof(visit)); 32 memset(num,0,sizeof(num)); 33 k=0; 34 int t=s; 35 handle(s); 36 visit[s]=1;//这里用标记来处理出现的数是因为防止某些式子不会循环到s,所以这里用标记的方法来解决! 37 // 2 4 8 0 0 0。。。。。。这样的情况也可以停止 38 while(visit[s=(a*s+b)%c]!=1)//这里的处理很巧妙的处理的两种问题 39 { 40 visit[s]=1; 41 handle(s); 42 } 43 44 45 char ans[17]; 46 int on,z; 47 48 for(i=0;i<=15;i++) 49 { on=0;z=0; 50 for(j=0;j<k;j++) 51 { 52 if(num[j][i]==0) 53 z++; 54 else 55 on++; 56 } 57 if(z==k) ans[i]='0'; 58 else if(on==k) ans[i]='1'; 59 else ans[i]='?'; 60 } 61 ans[16]='\0'; 62 puts(ans); 63 } 64 return 0; 65 }
learned: no matter how short the time, must read the problem carefully!
Problem C: POJ 3697 USTC campus network problem link adress:http://poj.org/problem?id=3697
brute force bfs;
1 #include<iostream> 2 #include<cstring> 3 #include<queue> 4 #include<vector> 5 #include<cstdio> 6 using namespace std; 7 #define MAX 10005 8 int n,m; 9 vector<int>map[MAX]; 10 int BFS() 11 { 12 queue<int>q; 13 int cur,i,count; 14 count=0; 15 bool used[MAX]; 16 int p[MAX]; 17 memset(used,0,sizeof(used)); 18 memset(p,0,sizeof(p)); 19 used[1]=true; 20 q.push(1); 21 while(!q.empty()) 22 { 23 cur=q.front(); 24 q.pop(); 25 for(i=0;i<map[cur].size();i++) 26 { 27 28 p[map[cur][i]]=cur; 29 } 30 for(i=1;i<=n;i++) 31 { 32 if(p[i]!=cur&&!used[i]) 33 { 34 count++; 35 used[i]=true; 36 q.push(i); 37 } 38 } 39 40 } 41 return count; 42 } 43 int main() 44 { 45 int flag=1; 46 while(scanf("%d%d",&n,&m)) 47 { 48 if(n+m==0) break; 49 int i,j; 50 for(i=1;i<=n;i++) 51 map[i].clear(); 52 53 for(i=0;i<m;i++) 54 { 55 int a,b; 56 scanf("%d%d",&a,&b); 57 map[a].push_back(b); 58 map[b].push_back(a); 59 } 60 int ans=BFS(); 61 printf("Case %d: %d\n",flag++,ans); 62 } 63 return 0; 64 }
Problem D:POJ 3662 problem link adress:http://poj.org/problem?id=3662
I cann't work it out now!
Problem F POJ 3660 Cow contest Problem link adress:http://poj.org/problem?id=3660
Problem analysis: For example, if you want to determine you rank in you class, what's you need to know?
Yes,you just need to know how many people before you and how many people after you,and then you rank are determined.
So if there are N cows,for the i-th cow,if he win x times and lose y times,and if x+y=n-1 ,the i-th cow's rank can be determined.
To make sure the every two cows relation,we need to use the Floyd algorithm!
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 using namespace std; 5 int map[105][105]; 6 int n,m; 7 int ans; 8 void Floyd() 9 { 10 int i,j,k; 11 for(i=1;i<=n;i++) 12 for(j=1;j<=n;j++) 13 for(k=1;k<=n;k++) 14 { 15 if(map[k][i]==1&&map[i][j]==1) 16 map[k][j]=1; 17 } 18 } 19 int main() 20 { 21 int i,j; 22 while(scanf("%d%d",&n,&m)!=EOF) 23 { 24 memset(map,0,sizeof(map)); 25 for(i=1;i<=m;i++) 26 { 27 int a,b; 28 scanf("%d%d",&a,&b); 29 map[a][b]=1; 30 } 31 Floyd(); 32 int los,win; 33 ans=0; 34 for(i=1;i<=n;i++) 35 { 36 los=0;win=0; 37 for(j=1;j<=n;j++) 38 { 39 if(map[i][j]==1) 40 win++; 41 if(map[j][i]==1) 42 los++; 43 } 44 if(win+los==n-1) 45 ans++; 46 } 47 printf("%d\n",ans); 48 49 50 } 51 return 0; 52 } 53 54
Post by heat_nan from zzuli @ 2013-03-18 18:45