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:不用并查集可不可以做?In Reply To:不用并查集可不可以做? Posted by:380030144 at 2013-03-24 00:10:15 > 我的想法是,设个数组,都初始化为0,在输入两个同学是同一宗教时,把较大的一个对应的数组的值为1,之后再输入完之后,数不是不是1的元数的个数 > 但是我的代码总是wa,求解。 #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<stdlib.h> #include<math.h> using namespace std; int pre[500500]; int max(int x,int y) { int i=x>y?x:y; return i; } int main() { int i,j=0; int n; long long int m; int x,y; int tmp=0; int sum=0; while(1) { j++; sum=0; scanf("%d",&n); cin>>m; if(n==0) break; memset(pre,0,sizeof(pre)); // printf("%d\n",pre[2]); for(i=0;i<m;i++) { scanf("%d %d",&x,&y); if(x!=y && x!=0 && y!=0) { tmp=max(x,y); pre[tmp]=1; } } for(i=1;i<=n;i++) { if(pre[i]==0) sum++; } printf("Case %d: %d\n\n",j,sum); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator