暑假集训(4)第八弹——— 组合(hdu1524)

题意概括:你已经赢得两局,最后一局是N个棋子往后移动,最后一个无法移动的玩家失败。

题目分析:有向无环图sg值游戏,尼姆游戏的抽象表达。得到每个棋子的sg值之后,把他们异或起来,考察异或值是否为0.

 1 #include "cstdio"
 2 int figure[1004][1004];
 3 int sg[1004];
 4 int t;
 5 void fbegin()
 6 {
 7     for (int i=0;i<1004;i++)
 8      {
 9         sg[i] = -1;
10         for (int j=0;j<1004;j++)
11         {
12              figure[i][j] = -1;
13         }
14      }
15 }
16 int dfs(int n)
17 {
18     if (sg[n] != -1)
19          return  sg[n];
20     int hash[1004] = {0};
21     for (int i=0;i<t;i++)
22     {
23         if (figure[n][i] == 1)
24                 hash[dfs(i)] = 1;
25     }
26     for (int i=0;;i++)
27         if (hash[i] == 0)
28             return  sg[n] = i;
29 }
30 int main()
31 {
32     int a,b,sum;
33     while (scanf ("%d",&t) != EOF)
34     {
35         fbegin();
36         for (int i=0;i<t;i++)
37         {
38             scanf ("%d",&a);
39             if (!a)
40                sg[i] = 0;
41             while (a-- && scanf ("%d",&b))
42             {
43                 figure[i][b] = 1;
44             }
45         }
46         while (scanf ("%d",&a) && a)
47         {
48             sum = 0;
49             while (a--)
50             {
51                 scanf ("%d",&b);
52                 sum ^= dfs(b);
53             }
54             printf ("%s\n",sum?"WIN":"LOSE");
55         }
56
57     }
58     return 0;
59 }

时间: 2024-12-28 01:12:46

暑假集训(4)第八弹——— 组合(hdu1524)的相关文章

暑假集训(1)第八弹 -----Catch the cow(Poj3984)

Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, }; 它表示一个迷宫,其中的1表示墙壁,0表示可以走的路,只能横着走或竖着走,不能斜着走,要求编程序找出从左上角到右下角的最短路线. Input 一个5 × 5的二维数组,表示一个迷宫.数据保证有唯一解. Output 左上角到右下角的最短路径,格式如样例所示. Sa

暑假集训(2)第八弹 ----- Hero(hdu4310)

K - Hero Crawling in process... Crawling failed Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description When playing DotA with god-like rivals and pig-like team members, you have to face an embarrassing

暑假集训(4)第七弹——— 组合(hdu1850)

题意概括:你赢得了第一局.魔鬼给出的第二局是,如果有N堆牌,先手的人有几种可能胜利. 问题分析:尼姆游戏,先得到n堆牌的数量异或和,再将异或和与每一个牌组的数量异或,如果结果小于原牌组数量 则可能++. 1 #include "cstdio" 2 int M[104]; 3 int main() 4 { 5 int m,sum,f; 6 while (scanf ("%d",&m) && m) 7 { 8 sum=f=0; 9 for (in

暑假集训(4)第六弹——— 组合(poj1067)

题意概括:上一次,你成功甩掉了fff机械兵.不过,你们也浪费了相当多的时间.fff团已经将你们团团包围,并且逐步 逼近你们的所在地.面对如此危机,你不由得悲观地想:难道这acm之路就要从此中断?虽然走上这条路不过数日,好 歹你也帮助过许多生物脱离困境啊.怎么就好人......等等,你翻了翻包裹,拿出了一个颇为古旧的黄铜瓶,瓶口用锡 纸封着,这瓶子是上次那只青蛙送的,它说危难之际,打开瓶口便可解围.“娑殚之瓶!“,谁知刚拿出瓶子,就听到小A 惊讶的呼声,“它也许能帮我们脱离困境,不过恐怕会有些危险

暑假集训(2)第八弹 ----- Points on Cycle(hdu1700)

Points on Cycle Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description There is a cycle with its center on the origin. Now give you a point on the cycle, you are to find out the other two points on it, to maximize th

暑假集训(2)第五弹 ----- Who&#39;s in the Middle(poj2388)

G - Who's in the Middle Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description FJ is surveying his herd to find the most average cow. He wants to know how much milk this 'median

暑假集训(2)第七弹 -----今年暑假不AC(hdu2037)

J - 今年暑假不AC Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description “今年暑假不AC?” “是的.” “那你干什么呢?” “看世界杯呀,笨蛋!” “@#$%^&*%...” 确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了. 作为球迷,一定想看尽量

暑假集训(1)第七弹 -----Oil Deposits(Poj1562)

Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It

暑假集训(1)第三弹 -----Dungeon Master(Poj2251)

Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot m