http://acm.timus.ru/problem.aspx?space=1&num=1282

简单博弈 注意题意的理解

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
#include<cmath>using namespace std;
//#pragma comment(linker,"/STACK:1000000000,1000000000")#define LL long longconst int INF=0x3f3f3f3f;
const int N=1005;
int win[N];
int L[N];
int head[N];
struct node
{int j,next;
}side[N];
int I;
void Add(int i,int j)
{side[I].j=j;side[I].next=head[i];head[i]=I++;
}
int dfs(int x,int w)
{if(L[x]!=-2)return L[x];int k=(w==1)?-1:1;for(int t=head[x];t!=-1;t=side[t].next){int l=side[t].j;if(w==1)k=max(k,dfs(l,-w));elsek=min(k,dfs(l,-w));}return k;
}
int main()
{//freopen("data.txt","r",stdin);int n;while(scanf("%d",&n)!=EOF){I=0;memset(head,-1,sizeof(head));for(int i=1;i<=n;++i){L[i]=-2;win[i]=-2;}for(int i=2;i<=n;++i){char c;int f,k;cin>>c>>f;//cout<<c<<" "<<f<<endl;Add(f,i);if(c=='L'){cin>>k;L[i]=k;}}int tmp=dfs(1,1);if(tmp==1)cout<<"+1"<<endl;else if(tmp==-1)cout<<"-1"<<endl;elsecout<<"0"<<endl;}return 0;
}

转载于:https://www.cnblogs.com/liulangye/archive/2012/10/18/2730026.html

1282. Game Tree相关推荐

  1. AC日记——约瑟夫问题 codevs 1282

    1282 约瑟夫问题  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 大师 Master 题解  查看运行结果 题目描述 Description 有编号从1到N的N个小朋友在玩 ...

  2. 107. Binary Tree Level Order Traversal II

    题目 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from l ...

  3. 102. Binary Tree Level Order Traversal

    题目 Binary Tree Level Order Traversal 层次遍历二叉树 链接 Given a binary tree, return the level order traversa ...

  4. Python---哈夫曼树---Huffman Tree

    今天要讲的是天才哈夫曼的哈夫曼编码,这是树形数据结构的一个典型应用. !!!敲黑板!!!哈夫曼树的构建以及编码方式将是我们的学习重点. 老方式,代码+解释,手把手教你Python完成哈夫曼编码的全过程 ...

  5. [Java]LeetCode297. 二叉树的序列化与反序列化 | Serialize and Deserialize Binary Tree

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  6. Code Forces Bear and Forgotten Tree 3 639B

    B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...

  7. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

  8. datagrid底部显示水平滚动_DevExpress WPF v19.1:Data Grid/Tree List等控件功能增强

    行业领先的.NET界面控件DevExpress 日前正式发布v19.1版本,本站将以连载的形式介绍各版本新增内容.在本系列文章中将为大家介绍DevExpress WPF v19.1中新增的一些控件及部 ...

  9. java easyui tree例子_EasyUI Tree的简单使用

    此前写过zTree插件的demo,没有记录下来,这次记录一下EasyUI的Tree. 实现效果:获取数据库表的数据,以树结构的形式展示出来. 树结构数据分为同步加载和异步加载,同步加载就是初始化加载时 ...

最新文章

  1. bug诞生记——不定长参数隐藏的类型问题
  2. LeetCode House Robber II(动态规划)
  3. 三次握手,四次挥手的过程??为什么三握??
  4. 四则运算 结对编程
  5. oracle自带的加密函数,oracle 的加密解密函数
  6. crc16码表的使用_查表法计算CRC16校验值
  7. pytorch根据特征图训练LSTM Stacked AutoEncoder
  8. Fragment学习(二): 管理Fragment和Fragment通讯
  9. 端端Clouduolc与百度云盘等公有云同步的区别
  10. 半胱氨酸蛋白酶Caspase-8 Inhibitor I, 886462-83-5
  11. OA系统是什么意思?企业为什么要用OA办公系统软件?
  12. gdiPlus的imag::fromFile函数调用返回为空
  13. 904. 水果成篮(数组、滑动窗口)
  14. K8S——存储-Secret
  15. C++ qt实现打开关闭状态按钮
  16. Android 之网络
  17. 任何产品需求,挖到最后都是人性
  18. 当代年轻人熬夜晚睡的原因找到了!
  19. WmiPrvSE.exe内存占用异常
  20. 推荐一款免费的文件夹加密软件 Free Encrypt Folder 加密耗子

热门文章

  1. 简单粗暴告诉你什么是区块链
  2. PAT(甲级)2018年冬季考试 7-1 Google Recruitment
  3. 几何图形在logo设计中的有哪些情感意义?
  4. vue下的bootstrap table + jquery treegrid, treegrid无法渲染的问题
  5. vue下实现textarea类似密码框的功能之探索input输入框keyup,keydown,input事件的触发顺序...
  6. 2.1:CGPROGRAM
  7. jupyter notebook用法积累(快捷键)
  8. 大数据处理也要安全--关于MaxCompute的安全科普
  9. C++对象赋值的四种方式
  10. vue router 入门笔记