hdu1524博弈SG

hdu1524博弈SG

A Chess Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1100    Accepted Submission(s): 504

Problem Description
Let’s design a new chess game. There are N positions to hold M chesses in this game. Multiple chesses can be located in the same position. The positions are constituted
as a topological graph, i.e. there are directed edges connecting some positions, and no cycle exists. Two players you and I move chesses alternately. In each turn the player
should move only one chess from the current position to one of its out-positions along an edge. The game does not end, until one of the players cannot move chess any
more. If you cannot move any chess in your turn, you lose. Otherwise, if the misfortune falls on me… I will disturb the chesses and play it again. Do you want to challenge
me? Just write your program to show your qualification!
 

 

Input
Input contains multiple test cases. Each test case starts with a number N (1 <= N <= 1000) in one line. Then the following N lines describe the out-positions of each
position. Each line starts with an integer Xi that is the number of out-positions for the position i. Then Xi integers following specify the out-positions. Positions are
indexed from 0 to N-1. Then multiple queries follow. Each query occupies only one line. The line starts with a number M (1 <= M <= 10), and then come M integers,
which are the initial positions of chesses. A line with number 0 ends the test case.
 

 

Output
There is one line for each query, which contains a string “WIN” or “LOSE”. “WIN” means that the player taking the first turn can win the game according to a clever
strategy; otherwise “LOSE” should be printed.
 

 

Sample Input
4 2 1 2 0 1 3 0 1 0 2 0 2 0 4 1 1 1 2 0 0 2 0 1 2 1 1 3 0 1 3 0

 

 

Sample Output
WIN WIN WIN LOSE WIN

 用SG函数做的:

hdu1524博弈SG
hdu1524博弈SG

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <algorithm>
 4 #include <string.h>
 5 #include <math.h>
 6 #include <vector>
 7 #include <stack>
 8 #include <queue>
 9 using namespace std;
10 #define ll long long int
11 vector<int> a[1100];
12 int z[1100];
13 int n;
14 int dfs(int x)
15 {
16     if(z[x]!=-1)return z[x];
17     int size=a[x].size();
18     int i;
19     int c[n];
20     memset(c,0,sizeof(c));
21     for(i=0;i<size;i++)
22     {
23         c[dfs(a[x][i])]=1;
24     }
25     for(i=0;i<n;i++)
26     if(!c[i])
27     {
28         z[x]=i;
29         break;
30     }
31     return z[x];
32 }
33 int main()
34 {
35     while(cin>>n)
36     {
37         bool b[n];
38         memset(z,-1,sizeof(z));
39         memset(b,0,sizeof(b));
40         int i,j,m,x;
41         for(i=0;i<n;i++)
42         {
43             a[i].clear();
44             cin>>m;
45             for(j=0;j<m;j++)
46             {
47                 cin>>x;
48                 a[i].push_back(x);
49                 b[x]=1;
50             }
51         }
52         for(i=0;i<n;i++)
53         {
54             if(!b[i])
55             dfs(i);
56         }
57         while(cin>>m&&m)
58         {
59             int sum=0;
60             for(i=0;i<m;i++)
61             {
62                 cin>>x;
63                 sum^=z[x];
64             }
65             if(sum)
66             cout<<"WIN"<<endl;
67             else cout<<"LOSE"<<endl;
68         }
69     }
70 }

View Code

 

 

 

转载于:https://www.cnblogs.com/ERKE/p/3263476.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/110045.html原文链接:https://javaforall.net

(0)
上一篇 2021年8月25日 下午3:00
下一篇 2021年8月25日 下午3:00


相关推荐

  • winhex手工恢复分区表,用winhex恢复误格式化的分区

    winhex手工恢复分区表,用winhex恢复误格式化的分区

    2026年3月12日
    4
  • jquery Ajax请求中显示Loading…

    jquery Ajax请求中显示Loading…

    2021年9月7日
    123
  • TLSF内存分配器记录[通俗易懂]

    TLSF内存分配器记录[通俗易懂]论文:《TLSF:aNewDynamicMemoryAllocatorforReal-TimeSystems》这也是Unity底层使用的内存分配器。我直接从论文中间部分开始看。firstlevel存的是每个内存分配大小,从2的四次方到2的31次方。而对应每个大小,又指向一个二级列表,里面被分成4级,每一级的范围认为是同一类。1表示空闲,所以只有2的六次方和2的15次方块是空闲的。再看它指向的二级列表。只有2的六次方+16到2的6次方+32的这个.

    2022年6月26日
    48
  • 【JVM调优工具】JVM调优工具[通俗易懂]

    【JVM调优工具】JVM调优工具[通俗易懂]一、JVM调优工具1.jstat工具java程序默认使用的xmx_为什么JAVA进程占用内存会超过Xmx设置_保瓶儿的博客-CSDN博客

    2022年5月31日
    29
  • web后端语言_C/C++作为web后端语言的缺点

    web后端语言_C/C++作为web后端语言的缺点C/C++C语言虽然是非常贴近操作系统的语言,能和操作系统API很好的交互,但是C语言并没有现代化工程开发所需要的面向对象功能,当然也缺乏泛型之类的功能,如果以CGI的形式开发,那么缺点非常明显,这也是第二代后端平台兴起的原因。C++具有现代化工程开发所需要的各种功能,但是它同样有缺点:缺乏字符串处理,Web开发最主要的就是字符串的处理,所有的一切几乎都要和字符串打交道,但是C…

    2022年6月25日
    48
  • mysql转换字符串为数字_mysql字符与数字转换「建议收藏」

    mysql转换字符串为数字_mysql字符与数字转换「建议收藏」本节内容:mysql字符与数字转换的方法1,将字符的数字转成数字,比如’0’转成0可以直接用加法实现。例如:将pony表中的d进行排序,可d的定义为varchar:复制代码代码示例:select*fromponyorderby(d+0)2,在进行ifnull处理时,比如ifnull(a/b,’0′)会导致a/b成了字符串,因此需要把’0’改成0。3,比较数字和varchar时…

    2022年5月30日
    103

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号