标签:des style blog http color java os io
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 435 Accepted Submission(s): 204
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<map> 9 10 #define N 1005 11 #define M 15 12 #define mod 1000000007 13 #define mod2 100000000 14 #define ll long long 15 #define maxi(a,b) (a)>(b)? (a) : (b) 16 #define mini(a,b) (a)<(b)? (a) : (b) 17 18 using namespace std; 19 20 int cnt; 21 int p; 22 int i,j; 23 int a[N][N]; 24 int c[N][N]; 25 int cc[N]; 26 int ans[N]; 27 28 int main() 29 { 30 //ini(); 31 //freopen("data.in","r",stdin); 32 //scanf("%d",&T); 33 //for(int cnt=1;cnt<=T;cnt++) 34 //while(T--) 35 cnt=1; 36 while(scanf("%d",&p)!=EOF) 37 { 38 if(p==0) break; 39 printf("Case #%d:",cnt);cnt++; 40 memset(c,0,sizeof(c)); 41 memset(cc,0,sizeof(cc)); 42 for(i=0;i<p;i++) 43 { 44 for(j=1;j<=p;j++){ 45 scanf("%d",&a[i][2*j-1]); 46 cc[ a[i][2*j-1] ]++; 47 scanf("%d",&a[i][2*j]); 48 cc[ a[i][2*j] ]++; 49 } 50 } 51 52 int ma=cc[0]; 53 int index=0; 54 for(i=0;i<p;i++){ 55 if(cc[i]>ma){ 56 ma=cc[i];index=i; 57 } 58 } 59 ans[0]=index; 60 61 memset(cc,0,sizeof(cc)); 62 63 for(i=0;i<p;i++) 64 { 65 for(j=1;j<=p;j++){ 66 if(c[i][ a[i][2*j-1] ]==0){ 67 c[i][ a[i][2*j-1] ]=1; 68 cc[i]++; 69 } 70 } 71 if(cc[i]==1){ 72 if(ans[0]!=i) ans[1]=i; 73 } 74 else{ 75 ans[ cc[i] ]=i; 76 } 77 } 78 79 for(i=0;i<p;i++) printf(" %d",ans[i]); 80 printf("\n"); 81 } 82 83 84 85 return 0; 86 }
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/njczy2010/p/3914578.html