标签:des style blog http color io os ar java
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)
Total Submission(s): 1466 Accepted Submission(s): 433
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 #include <queue> 6 #include <vector> 7 #include <map> 8 #include <set> 9 using namespace std; 10 11 int b[105]; 12 __int64 num; 13 void bing(int st,int mid,int end,int a[]) 14 { 15 int i, j, k; 16 for(i=st;i<=end;i++) 17 b[i]=a[i]; 18 i=st;j=mid+1;k=st; 19 while(i<=mid&&j<=end) 20 { 21 if(b[i]<=b[j]) 22 { 23 a[k++]=b[i++]; 24 } 25 else{ 26 a[k++]=b[j++]; 27 num+=(mid-i+1); 28 } 29 } 30 while(i<=mid) 31 a[k++]=b[i++]; 32 while(j<=end) 33 a[k++]=b[j++]; 34 } 35 void msort(int st,int end,int a[]) 36 { 37 if(st<end) 38 { 39 int t=(st+end)/2; 40 msort(st,t,a); 41 msort(t+1,end,a); 42 bing(st,t,end,a); 43 } 44 } 45 main() 46 { 47 int n, i, j, a, k, k1, t, f; 48 int a1[105], a2[105], c1[105], c2[105], d1[105], d2[105]; 49 cin>>t; 50 int x, y, z1, z2; 51 while(t--){ 52 k=0; 53 k1=1; 54 for(i=1;i<=24;i++){ 55 scanf("%d",&a); 56 if(i==1||i==2||i==3||i==8||i==17||i==22||i==23||i==24){ 57 a1[k++]=a; 58 } 59 else{ 60 c1[k1++]=a; 61 } 62 } 63 64 k=0;k1=1; 65 for(i=1;i<=24;i++){ 66 scanf("%d",&a); 67 if(i==1||i==2||i==3||i==8||i==17||i==22||i==23||i==24){ 68 a2[k++]=a; 69 } 70 else{ 71 c2[k1++]=a; 72 } 73 } 74 75 for(i=0;i<8;i++){ 76 if(a1[i]==0){ 77 if(i==0||i==2) swap(a1[i],c1[1]); 78 else if(i==1||i==3) swap(a1[i],c1[4]); 79 else if(i==4||i==6) swap(a1[i],c1[13]); 80 else if(i==5||i==7) swap(a1[i],c1[16]); 81 } 82 } 83 for(i=0;i<8;i++){ 84 if(a2[i]==0){ 85 if(i==0||i==2) swap(a2[i],c2[1]); 86 else if(i==1||i==3) swap(a2[i],c2[4]); 87 else if(i==4||i==6) swap(a2[i],c2[13]); 88 else if(i==5||i==7) swap(a2[i],c2[16]); 89 } 90 } 91 k=1; 92 for(i=1;i<=16;i++) { 93 if(!c1[i]) x=(i-1)/4+1; 94 else d1[k++]=c1[i]; 95 } 96 k=1; 97 for(i=1;i<=16;i++) { 98 if(!c2[i]) y=(i-1)/4+1; 99 else d2[k++]=c2[i]; 100 } 101 /* for(i=0;i<8;i++) printf("%d ",a1[i]); 102 cout<<endl; 103 for(i=0;i<8;i++) printf("%d ",a2[i]); 104 cout<<endl; 105 for(i=1;i<=16;i++) printf("%d ",c1[i]); 106 cout<<endl; 107 for(i=1;i<=16;i++) printf("%d ",c2[i]); 108 cout<<endl;*/ 109 f=1; 110 for(i=0;i<8;i++){ 111 if(a1[i]!=a2[i]){ 112 f=0;break; 113 } 114 } 115 if(!f){ 116 printf("Y\n");continue; 117 } 118 num=0; 119 msort(1,15,d1); 120 z1=num; 121 num=0; 122 msort(1,15,d2); 123 z2=num; 124 125 if(((z1+z2)%2)==((abs(y-x))%2)){ 126 printf("N\n"); 127 } 128 else printf("Y\n"); 129 } 130 }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/qq1012662902/p/4007266.html