2019 杭电多校 Just an Old Puzzle HDU - 6620 数字华容道有解

题目链接:https://vjudge.net/problem/HDU-6620

题解:

#include 
using namespace std;
int a[20];
int n;
int main( ) {
    int T;
    scanf("%d", &T);
    int flag, x, ans;
    while(T--) {
        ans = 0;
        for(int i = 1; i <= 16; i++) {
            scanf("%d", &a[i]);
            if(a[i] == 0) flag = i / 4 + (i % 4 != 0);
            else {
                for(int j = 1; j < i; j++) {
                    if(a[j] == 0) continue;
                    if(a[j] > a[i]) ans++; 
                }
            }
        }
    //    cout << flag << " " << ans << endl;
        printf((4-flag) % 2 == ans % 2 ? "Yes\n" : "No\n");
    }
    return 0;
}

 

你可能感兴趣的:(思维,数学)