poj解题报告——2425
来源:互联网 发布:c语言中取反 编辑:程序博客网 时间:2024/06/05 08:18
题意:给一个有向无环图,给M枚棋子,每个人可以移动一个棋子,棋子可以重叠。直到无法移动者Lose
算法:按照Topo顺序,依次计算每个点的SG值,然后做合并,注意,先dfs后合并,判断重复
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int NN=1001;int mp[NN][NN];int x[NN],n;int SG[NN];int lis[NN];void init(){memset(mp,0,sizeof(mp));for(int i=0;i<n;i++){scanf("%d",&mp[i][0]);for(int j=1;j<=mp[i][0];j++)scanf("%d",&mp[i][j]);}}void dfs(int x){int i;if(SG[x]!=-1) return;for(i=1;i<=mp[x][0];i++)dfs(mp[x][i]);memset(lis,0,sizeof(lis));for(i=1;i<=mp[x][0];++i)lis[SG[mp[x][i]]]=1;SG[x]=0;while(lis[SG[x]]==1) SG[x]++;}int main(){while(~scanf("%d",&n)){init();memset(SG,-1,sizeof(SG));for (int i=0;i<n;i++) dfs(i);int m,p;while(scanf("%d",&m),m){int tmp;p=0;for (int i=0;i<m;i++){scanf("%d",&tmp);p^=SG[tmp];}if(p==0)printf("LOSE\n");else printf("WIN\n");}}return 0;}
0 0
- poj解题报告——2425
- POJ 1088 滑雪——解题报告
- POJ 1047——解题报告
- poj解题报告——poj1006
- poj解题报告——1032
- poj解题报告——1061
- poj解题报告——1450
- poj解题报告——1002
- poj解题报告——2109
- poj解题报告——1218
- poj解题报告——1250
- poj解题报告——1012
- poj解题报告——3299
- poj解题报告——2209
- poj解题报告——2406
- poj解题报告——2242
- poj解题报告——1401
- poj解题报告——1328
- hdu1870愚人节的礼物之天呐你们为什么要骗我用栈才能过。。。大水题。。。
- java中Date与String的相互转化
- IT项目管理(原书第7版)——互动出版网
- swirl 10: lapply and sapply
- 闪电特效算法
- poj解题报告——2425
- 如何使用Cocos2d-x 3.0制作基于tilemap的游戏:第二部分
- NSDictionary、NSMutableDictionary的基本用法
- Spark Graphx 构建graph和aggregateMessages聚合消息
- 乐点 Android SDK 积分墙开发者文档
- Fixing the Great Wall
- HDU - 2553 N皇后问题
- LeetCode 题解(167): Sqrt(x)
- 黑马程序员——OC笔记之购票系统应用实践