A Funny Game(POJ 2484)】的更多相关文章

题目链接:http://poj.org/problem?id=2484 这道题目大意是这样的,有n个硬币围成一圈,两个人轮流开始取硬币(假设他们编号从1到n),可以选择取一枚或者取相邻的两枚(相邻是指他们的编号相邻).在双方都采取最优策略取硬币的情况下,问谁最后会赢. 这道题目我一开始没有什么好的办法,n从1试到7,大致能发现n>=3的时候是Bob赢,否则是Alice赢. 可是为什么这样写正确呢?有没有严格一些的证明呢? 我查阅了许多资料,有了下边的理解,可能不是很准确,望纠正. n<=3的时…
http://poj.org/problem?id=2484 1和2时Alice必胜,3时Bob必胜,其他情况下Bob只需要在Alice取过之后取一次将剩下的硬币链平均分为两份,然后Alice怎么取Bob对称着取就可以了. 真是巧妙. 代码 #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<ma…
相比数据结构的题..感觉这种想啊想的题可爱多了~~~代码量还少.... 题目链接: http://poj.org/problem?id=2484 题意: 一圈n个硬币,两人轮流从中取一或两个硬币,(只能取相邻的两枚硬币),取完的获胜,问谁赢? 分析: 这里注意,连续的硬币中取出若干个后,被分割开的就不算连续的硬币了. 首先还是找是否存在对称状态,只要是存在对称状态,后手模仿先手,最后后手必赢. 假设先手第一次拿走了1或者2个硬币,圈被分裂成一条链,后手在链的中间部位拿走1或者2个硬币,将链分为两…
A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3861   Accepted: 2311 Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A mo…
A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4639   Accepted: 2855 Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A mo…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6397   Accepted: 3978 Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A move consists i…
题目链接: 传送门 A Funny Game Time Limit: 1000MS     Memory Limit: 10000K Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A move consists in removing one o…
Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 10 6) coins in a circle, as Figure 1 shows. A move consists in removing one or two adjacent coins, leaving all other coins untouched. At least…
一开始看这道博弈题的时候我就用很常规的思路去分析了,首先先手取1或者2个coin后都会使剩下的coin变成线性排列的长条,然后无论双方如何操作都是把该线条分解为若干个子线条而已,即分解为若干个子游戏而已,我想起刘汝佳的大白书上有类似的例题(不过复杂好多),于是便用同样的方法去做了,以sg(x)表示当前连续x个coin的状态的sg函数值,则当从左侧起分别取一个或相邻的两个时,不难得出其后继状态:sg(y)^sg(x-1-y)(0<=y<=(x-1)/2),sg(y)^sg(x-2-y)(0<…
题目链接题意:有n个硬币排成一圈,两个人轮流操作,每次可以取走一个或者相邻的连个硬币(只算最开始相邻的,取之后才相邻的不算),问先手必胜还是必败. 这个题可以证明若n>=3,则先手必败.对称博弈若n>=3,先手第一次必然把这个环拆成一个链,然后无论这条链长度的奇偶,后手总是可以把这条链分成两条相等的链,于是先手在一条链上做什么,后手就可以做什么.知道先手无法操作,后手胜. #include<iostream> #include<cstdio> #include<a…
博弈. $n>=3$,后手赢,否则先手赢. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<map> #include<set> #inclu…
题目链接 #include<iostream> #include<cstdio> using namespace std; int main() { int n; while(scanf("%d",&n)&&n) {//alice先把环破坏,变成链,然后bob只要在链中间取1或2个 //连续的coins,让链变成左右对称的两条,bob就必胜 ||n==) printf("Alice\n"); else printf(&…
Problem description: n枚硬币排成一个圈,A和B轮流从中取一枚或两枚硬币,不过取两枚时,所取的两枚硬币必须是连续的.硬币取走之后留下空位,相隔空位的硬币视为不连续的.A开始先取,取走最后一枚硬币的一方获胜.当双方都采取最优策略时,谁会获胜? 0<=n<=100000 Input 1 Output A n的数据过大时,状态过多,动态规划和搜索都会超时. 考虑将所有硬币分成两个完全相同对称的状态: 实际上我们发现这个时候是必败态,因为无论自己采取什么策略,对手只要在另一组采取相…
题意:n枚硬币围成一个圈,每次每个人可以从中取走一枚或者相邻的两枚(如果两枚硬币原本中间隔着一枚硬币,后来被取走,这两枚硬币不算相邻).谁取走最后一枚硬币谁就赢了. 思路:我们可以找找规律. 首先,n为1和2的时候肯定是先手胜.n为3时,无论先手取1枚还是2枚,都会输. 当n大于等于4时,我们分成两种情况来讨论. 如果n为偶数,对于后手来说,总可以根据先手的做法,在对称的位置取走相同数量的硬币.先手必输. 如果n为奇数,对于后手来说,总可以在某处取走硬币后,使得剩下的硬币分成对称的两组,然后依照…
原题如下: A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7108   Accepted: 4464 Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows…
在介绍SG函数和SG定理之前我们先介绍介绍必胜点与必败点吧. 必胜点和必败点的概念:        P点:必败点,换而言之,就是谁处于此位置,则在双方操作正确的情况下必败.        N点:必胜点,处于此情况下,双方操作均正确的情况下必胜. 必胜点和必败点的性质:         1.所有终结点是 必败点 P .(我们以此为基本前提进行推理,换句话说,我们以此为假设)         2.从任何必胜点N 操作,至少有一种方式可以进入必败点 P.         3.无论如何操作,必败点P 都…
在介绍SG函数和SG定理之前我们先介绍介绍必胜点与必败点吧. 必胜点和必败点的概念:        P点:必败点,换而言之,就是谁处于此位置,则在双方操作正确的情况下必败.        N点:必胜点,处于此情况下,双方操作均正确的情况下必胜. 必胜点和必败点的性质:         1.所有终结点是 必败点 P .(我们以此为基本前提进行推理,换句话说,我们以此为假设)         2.从任何必胜点N 操作,至少有一种方式可以进入必败点 P.         3.无论如何操作,必败点P 都…
在介绍SG函数和SG定理之前我们先介绍介绍必胜点与必败点吧. 必胜点和必败点的概念:        P点:必败点,换而言之,就是谁处于此位置,则在双方操作正确的情况下必败.        N点:必胜点,处于此情况下,双方操作均正确的情况下必胜. 必胜点和必败点的性质:         1.所有终结点是 必败点 P .(我们以此为基本前提进行推理,换句话说,我们以此为假设)         2.从任何必胜点N 操作,至少有一种方式可以进入必败点 P.         3.无论如何操作,必败点P 都…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286   Accepted: 8603   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yumm…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 Description Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital le…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Accepted: 9197 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names t…
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时则按照横坐标从小到大输出. (0 <= x, y <= 32000) 要求输出等级0到n-1之间各等级的星星个数. 分析: 这道题不难想到n平方的算法,即从纵坐标最小的开始搜,每次找它前面横坐标的值比它小的点的个数,两个for循环搞定,但是会超时. 所以需要用一些数据结构去优化,主要是优化找 横坐…
poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23507   Accepted: 11012 Description The Head Elder of the tropical island of Lagrishan has a problem. A b…
Kaka's Matrix Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9567   Accepted: 3888 Description On an N × N chessboard with a non-negative number in each grid, Kaka starts his matrix travels with SUM = 0. For each travel, Kaka mo…
Friendship Time Limit: 2000MS   Memory Limit: 20000K Total Submissions: 10626   Accepted: 2949 Description In modern society, each person has his own friends. Since all the people are very busy, they communicate with each other only by phone. You can…