| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:诡异的WAIn Reply To:诡异的WA Posted by:wb_jerry at 2009-07-30 10:42:30 > #include <iostream>
> using namespace std;
> const int MaxN=2000;
> struct Bugs
> {
> int parent;
> int sex;
> }p[MaxN+1];
> int Find(int x)
> { int i,tmp1,tmp2,sex1,sex2;
> sex1=0;
> sex2=0;
> for(i=x;p[i].parent!=i;i=p[i].parent)
> sex1+=p[i].sex;
> while(i!=x)
> {
> tmp1=p[x].parent;
> tmp2=p[x].sex;
> p[x].parent=i;
> p[x].sex=(sex1-sex2)%2;
> x=tmp1;
> sex2+=tmp2;
> }
> return i;
> }
> bool Union(int R1,int R2,int r1,int r2)
> {
> if(R1==R2&&p[r1].sex!=p[r2].sex)
> return true;
> if(R1!=R2)
> {
> p[R1].parent=R2;
> int i;
> for(i=0;i<=1;i++)
> if((p[r1].sex+i+p[r2].sex)%2==1)
> break;
> p[R1].sex=i;
> return true;
> }
> return false;
> }
> int main()
> {
> int n,i,j;
> int N,K;
> bool right;
> int r1,r2;
> scanf("%d",&n);
> for(i=0;i<n;i++)
> {
> scanf("%d%d",&N,&K);
> for(j=1;j<=N;j++)
> {
> p[j].parent=j;
> p[j].sex=0;
> }
> right=true;
> for(j=1;j<=K;j++)
> {
> scanf("%d%d",&r1,&r2);
> if(right==false) continue;
>
> if(Union(Find(r1),Find(r2),r1,r2)==false) right=false;
> }
> /**********************************************************/
> cout<<"Scenario #"<<i+1<<":"<<endl;
> if(right==true) cout<<"No Suspicious bugs found!"<<endl;
> else cout<<"Suspicious bugs found!"<<endl;
> cout<<endl;
> /**********************************************************/
> }
> //system("Pause");
> }
>
>
> 这段程序交上去会WA,但如果把两条注释线间的输出部分改为
> printf("Scenario #%d:\n",i+1);
> if(right==false)
> {
> printf("Suspicious bugs found!\n\n");
> }
> else
> {
> printf("No suspicious bugs found!\n\n");
> }
> 就AC了,这实在有点看不明白,printf和cout到底有什么区别?
注意输出的大小写
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator