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


相关推荐

  • python跟pycharm的区别_python与pycharm有何区别[通俗易懂]

    python跟pycharm的区别_python与pycharm有何区别[通俗易懂]Python是一种计算机程序设计语言。是一种面向对象的动态类型语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的、大型项目的开发。PyCharm是Python的专用IDE,地位类似于Java的IDEEclipse。功能齐全的集成开发环境同时提供收费版和免费版,即专业版和社区版。PyCharm是安装最快的IDE,且安装后的…

    2022年8月28日
  • GB28181协议_gb28181版本

    GB28181协议_gb28181版本国家为了规范安防行业的设备平台互联互通,在2012年出台了GB/T-28181的第一版标准:这个版本我13年在工作中开发IPC设备使用过,当时觉得协议对流媒体的规范还是比较好(H.264+G711封装成PS流,再经过RTP协议进行实时传输),但是控制方面有很多不足,相对于当前流行的ONVIF协议在控制信令上还是有很多不足。去公安…

    2022年10月21日
  • vbs整人小代码大全

    事前准备:创建一个文件夹,后缀名为vbs,在里面编东西即可参考很多资料,如有不足请谅解文章目录vbs整人代码大全1.循环类1.1.一直说Youarefoolish!1.2.打开无数个计算器(慎用)1.3.重复说话100次1.4.不是循环但是很烦人1.5.给我按100次回车1.6.非常恶心的Alt+F42.问答类2.1.简单问答2.2.简单问答2.3.恐怖问答3.威胁类3.1.挟持回答3.2.挟持回答3.3虚惊一场结束vbs的代码完结vbs整人代码大全1.循环类1.1.一直说Youaref

    2022年4月7日
  • vscode常用插件推荐_梅林软件中心 常用插件

    vscode常用插件推荐_梅林软件中心 常用插件vscode插件推荐-献给所有前端工程师(2018.4.29更新)精选!15个必备的VSCode插件(前端类)30个极大提高开发效率的VisualStudioCode插件VSCode使用总结vscode几个常用插件推荐[补充]精选!15个必备的VSCode插件VSCode拓展插件推荐(HTML、Node、Vue、React开发均适用)VSCode折腾记-(4)…

    2022年9月30日
  • SSM整合(基于XML配置方式)

    SSM整合(基于XML配置方式)我们整合SSM框架时,大部分都是基于注解+XML配置方式。只因为结合这两种方法能够实现同样的效果,而且会更加的轻松。所以在此推荐朋友们用注解+XML配置的方式,基于注解+XML配置方式会另写一篇。但是有朋友和我说,怎么用纯XML方式整合SSM呢?我做了一个入门的整理,如果不足,请多多指教。本文是基于XML配置方式整合SSM框架,由于本人不太推荐这种方式。首先可以看一下完整的目录结构…

    2022年5月11日
  • 根据中奖概率抽奖算法

    根据中奖概率抽奖算法

    2021年6月16日

发表回复

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

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