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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • MYSQL 删除语句

    MYSQL 删除语句删除数据(DELETE)  如果你失忆了,希望你能想起曾经为了追求梦想的你。数据库存储数据,总会有一些垃圾数据,也会有一些不需要用的数据了,这些情况下,我们就可以删除这些数据,释放出一定的空间,给其他的数据使用使用前需注意:删除(DELETE),是删除一(条)行数据,图1里,有4条(行)数据,换句话说,你要删除第四条名字为“巴巴”的用户,那么关于他的id

    2022年6月24日
    49
  • C语言实现【关机程序】「建议收藏」

    C语言实现【关机程序】「建议收藏」在讲解关机程序前,必须得先知道一个库函数system(“shutdown-s-t60”)和system(“shutdown-a),其中“shutdown-s”表示关机,“shutdown-a”表示取消关机,“-t60”表示延迟60秒;而要使用该库函数就得引头文件#include<stdlib.h>。下面开始实现关机程序了:#include<stdio.h>#include<stdlib.h>#include<string.h>int.

    2022年7月22日
    9
  • ubuntu sublime安装及配置

    ubuntu sublime安装及配置

    2021年11月29日
    42
  • LeetCode[5]-最长回文子串_leetcode 合并区间

    LeetCode[5]-最长回文子串_leetcode 合并区间给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是 回文串 。返回 s 所有可能的分割方案。回文串 是正着读和反着读都一样的字符串。示例 1:输入:s = “aab”输出:[[“a”,”a”,”b”],[“aa”,”b”]]示例 2:输入:s = “a”输出:[[“a”]] 提示:1 <= s.length <= 16s 仅由小写英文字母组成题解暴搜class Solution {public: vector<vector<st

    2022年8月8日
    5
  • SGD随机梯度下降_随机梯度法

    SGD随机梯度下降_随机梯度法BGDvsSGDBGDvsSGD名词解释功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML图表FLowchart流程图导出与导入导出导入BGDvsSGD…

    2025年10月21日
    2
  • 人工智能催生出企业的神器,电话机器人

    人工智能催生出企业的神器,电话机器人

    2021年7月9日
    161

发表回复

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

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