标签:sort ima ++ pac using 空格 http img scanf
(咕在前面, 这是两道基本一样的题, 我都没有A掉, 但我觉得我写的十分正确!!!不想改了先放上来orz
思路:这个题真是妙啊qwq我特意新建了一个“妙啊”分类给它qwq(然而A不掉
贴上我可怜的无助的至今在两大oj还是wa的代码!(输入格式附和POJ
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 const int sz = 1000; 6 int n, m, flag, num = 0, cnt = 0, x, a[sz*sz], b[sz*sz]; 7 void merge_sort(int l, int r) { 8 if(r - l > 0) { 9 int mid = (l + r) >> 1; 10 int i = l, p = l, q = mid + 1; 11 merge_sort(l, mid); 12 merge_sort(mid+1, r); 13 while(q <= r|| p <= mid) { 14 if(q > r || (p <= mid && a[p] <= a[q])) 15 b[i++] = a[p++]; 16 else b[i++] = a[q++], cnt = cnt + mid - p + 1; 17 } 18 for(int i = l; i <= r; i++) 19 a[i] = b[i]; 20 } 21 } 22 int main() { 23 while(1) { 24 scanf("%d%d", &n, &m); 25 if(n==0&&m==0) break; 26 num = 0; 27 memset(a, 0, sizeof(a)); 28 memset(b, 0, sizeof(b)); 29 for(int i = 1; i <= n; i++) { 30 for(int j = 1; j <= m; j++) { 31 scanf("%d", &x); 32 if(x==0) { 33 flag = i; 34 continue; 35 } 36 a[++num] = x; 37 } 38 } 39 cnt = 0; 40 merge_sort(1, num); 41 if(m%2==1) { 42 if(cnt%2==1) { 43 if((n-flag)%2==1) printf("YES\n"); 44 else printf("NO\n"); 45 } 46 else { 47 if((n-flag)%2==1) printf("NO\n"); 48 else printf("YES\n"); 49 } 50 } 51 else { 52 if(cnt%2 == 0) printf("YES\n"); 53 else printf("No\n"); 54 } 55 } 56 return 0; 57 }
【练习——逆序对】N*M Puzzle / Simple Puzzle
标签:sort ima ++ pac using 空格 http img scanf
原文地址:https://www.cnblogs.com/Hwjia/p/9813319.html