hdu 1850 - Being a Good Boy in Spring Festival(简单博弈)

来源:互联网 发布:黑科技网络怎么使用 编辑:程序博客网 时间:2024/05/16 00:35

思路:

    尼姆博弈的变形, 对于每个堆都遍历一下,若起始状态已是T态,则ans = 0;   否则,就枚举第一步需要变动的堆i,求其他n-1个数a[]的异或值temp,

    如果temp<a[i],则ans加一,否则就不加,代表这一堆目前无法处理。

代码如下:

const int M = 105;int a[M];int main(){        int n;        while(~scanf("%d", &n) && n) {                for(int i = 1; i <= n; ++i)                        scanf("%d", &a[i]);                int ans = 0, pre = 0, cur = 0;                for(int i = 1; i <= n; ++i) {                        cur = pre;                        for(int j = i+1; j <= n; ++j)                                cur ^= a[j];                        pre ^= a[i];                        ans += (cur<a[i]);                }                printf("%d\n", ans);        }        return 0;}


原创粉丝点击