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


相关推荐

  • jsonp的实现原理_jsonp为什么要提供回调函数

    jsonp的实现原理_jsonp为什么要提供回调函数前几天看了动脑老师老宋讲的jsonp原理,觉得很受用,现做下笔记。什么是跨域:跨域是浏览器同源策略而产生的,在不同协议,不同端口,不同域名下(以上任意一个不同都算是跨域)的两个服务之间是无法互相访问的。举例:http://www.baidu.com/index.html调用http://www.baidu.com/server.php(非跨域)http

    2025年8月6日
    2
  • 【金融市场基础知识】——中国的金融体系(一)[通俗易懂]

    【金融市场基础知识】——中国的金融体系(一)[通俗易懂]阅读之前看这里????:博主是一名正在学习证券知识的学生,在每个领域我们都应当是学生的心态,也不应该拥有身份标签来限制自己学习的范围,所以博客记录的是在学习过程中一些总结,也希望和大家一起进步,在记录之时,未免存在很多疏漏和不全,如有问题,还请私聊博主指正。博客地址:天阑之蓝的博客,学习过程中不免有困难和迷茫,希望大家都能在这学习的过程中肯定自己,超越自己,最终创造自己。目录中国的金融体系(一)一、中国金融市场的历史、现状及影响因素1、新中国成立以来我国金融市场的发展历史★2、我国金融市场的发展现状

    2022年5月27日
    68
  • try catch 对性能影响

    try catch 对性能影响引言之前一直没有去研究trycatch的内部机制,只是一直停留在了感觉上,正好这周五开会交流学习的时候,有人提出了相关的问题。借着周末,正好研究一番。讨论的问题当时讨论的是这样的问题:比较下面两种trycatch写法,哪一种性能更好。for(inti=0;i<1000000;i++){try{Ma

    2022年6月16日
    56
  • VeryCD转型的应对措施,让我们继续分享互联网!!!

    VeryCD转型的应对措施,让我们继续分享互联网!!!
    昨天在家里,看着电影听着歌,忽然VeryCD就被和谐了!有电驴的日子才是好日子啊!我还想下【告白】呢!我还想下【大地惊雷】呢!……
    已经有不少同学注意到了,VeryCD的音乐区被和谐了,电影区和剧集区也不提供下载链接了,俨然变成一个在线视频网站。那么高清电影、剧集,音乐专辑、电影原声就此离我们远去了?不!
    VeryCD怂掉也是迟早的事儿,它在中国光明正大的推广盗版如此之久已经是一个奇迹了,但VC倒了并不会影响我们下载emule资源。简单来说VeryCD是一个商业公司,

    2022年7月15日
    18
  • 5G/NR SSB学习总结[通俗易懂]

    5G/NR SSB学习总结[通俗易懂]6.1SSB概念同步信号和PBCH块(SynchronizationSignalandPBCHblock,简称SSB),它由主同步信号(PrimarySynchronizationSignals,简称PSS)、辅同步信号(SecondarySynchronizationSignals,简称SSS)、PBCH三部分共同组成。6.2SSB特征…

    2022年6月30日
    36
  • java中%c%n是什么意思_在编码时如何使用\r与\n,两者的区别

    java中%c%n是什么意思_在编码时如何使用\r与\n,两者的区别\r与\n到底有何区别,编码的时候又应该如何使用,我们下面来了解一下。区别:\r:全称:carriagereturn(carriage是“字车”的意思,打印机上的一个部件)简称:return缩写:rASCII码:13作用:把光标移动到当前行的最左边\n:全称:newline别名:linefeed缩写:nASCII码:10作用:把光标向下移动一行不同操作系统怎样表示“回车+换行”(即一行的结…

    2022年7月8日
    30

发表回复

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

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