2019年杭电多校第四场 HDU - 6620 Just an Old Puzzle(华容道)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6620

题意:华容道有无解法

题解:

 

#include <iostream>
#include <cstdio>
#include <cstring>
#define ll long long
const int maxn = 2e5+5;
using namespace std;

int c[30];

int lowbit(int a) {
    return (-a)&a;
}
void update(int a) {
    while(a<20) {
        c[a]++;
        a+=lowbit(a);
    }
}

int query(int a) {
    int ans=0;
    while(a) {
        ans+=c[a];
        a-=lowbit(a);
    }
    return ans;
}
int a[19], b[19];
int main()
{
    int T, n, sum = 0;
    scanf("%d", &T);
    while(T--) {
        memset(c,0,sizeof(c));
        int x, ans = 0, num=0;
        for(int i=0;i<16;i++){
            scanf("%d", &b[i]);
            if(b[i])a[num++]=b[i];
            else x=i;
        }
        for(int i = 0; i < 15;i++)
        {
            ans += (i - query(a[i]));
            update(a[i]);
        }
        if(ans % 2 == 0){
            int cnt = 4 - (x / 4 + 1);
            if(cnt % 2 == 0){
                printf("Yes\n");
            }
            else printf("No\n");
        }
        if(ans % 2 == 1){
            int cnt = 4 - (x / 4 + 1);
            if(cnt % 2 == 1){
                printf("Yes\n");
            }
            else printf("No\n");
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值