HDU 3590 PP and QQ(树上删边游戏 + anti-sg)
2015-11-25 03:39
495 查看
题意:
N<=100颗树,每棵数有m<=100个点,双方每次可以选择一棵树的一条边删去,并且把不与根相连的边一并删去,不能操作者赢
分析:
基本思路和树上删边游戏一致,不同的是anti−sg.
有结论:先手必胜当且仅当:
1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1
2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1
证明见贾志豪《组合游戏略述——浅谈SG游戏的若干拓展及变形》
代码:
N<=100颗树,每棵数有m<=100个点,双方每次可以选择一棵树的一条边删去,并且把不与根相连的边一并删去,不能操作者赢
分析:
基本思路和树上删边游戏一致,不同的是anti−sg.
有结论:先手必胜当且仅当:
1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1
2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1
证明见贾志豪《组合游戏略述——浅谈SG游戏的若干拓展及变形》
代码:
// // Created by TaoSama on 2015-11-24 // Copyright (c) 2015 TaoSama. All rights reserved. // //#pragma comment(linker, "/STACK:1024000000,1024000000") #include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <string> #include <set> #include <vector> using namespace std; #define pr(x) cout << #x << " = " << x << " " #define prln(x) cout << #x << " = " << x << endl const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; int n, k; struct Edge { int v, nxt; } edge[205]; int head[105], cnt; void addEdge(int u, int v) { edge[cnt] = (Edge) {v, head[u]}; head[u] = cnt++; } int dfs(int u, int f) { int ret = 0; for(int i = head[u]; ~i; i = edge[i].nxt) { int v = edge[i].v; if(v == f) continue; ret ^= 1 + dfs(v, u); } return ret; } int main() { #ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin); // freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout); #endif ios_base::sync_with_stdio(0); while(scanf("%d", &n) == 1) { int sg = 0, gOne = 0; for(int i = 1; i <= n; ++i) { int k; scanf("%d", &k); cnt = 0; memset(head, -1, sizeof head); for(int j = 1; j < k; ++j) { int u, v; scanf("%d%d", &u, &v); addEdge(u, v); addEdge(v, u); } int tmp = dfs(1, -1); sg ^= tmp; gOne += tmp > 1; } if(sg && gOne || !sg && !gOne) puts("PP"); else puts("QQ"); } return 0; }
相关文章推荐
- hdu 3590 (树的删边游戏+ANTI-SG)
- [岁月随想]感恩节前夕
- HDU 3094 A tree game(树上删边游戏)
- leetcode之Delete Node in a Linked List
- [Redux] Store Methods: getState(), dispatch(), and subscribe()
- No 11.11 in my dictionary
- CF Round#333 Div2 C. The Two Routes
- Android-存储方式(持久化数据的方式)
- [Redux] Introduction
- FFmpeg 学习资料
- node.js开发小项目的全过程 1 快速创建项目
- 双链表(C实现)
- CTP 下单返回错误: 没有报单权限 和字段错误需要注意的问题
- 两种链表的合并运算(一种带头结点的,一种不带头结点)
- leetcode之Remove Linked List Elements
- 源码编译安装mysql
- 2015年11月25 Java基础系列(二)Thread Runnable线程初级讲解
- javascript中操作节点的属性
- 精神污染图制作(matlab代码)
- <<Label_Name>>End Loop Label_Name;