uva 1561 - Cycle Game(推理)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=4336" style="">题目链接:uva 1561 - Cycle Game
题目大意:给出一个环,每次从起点開始,能够选择一个权值非0的边移动,移动后减掉权值至少1点。
不能移动的为失败。
解题思路:
- 1:有0的情况,假设有方向离权值为0的边的步数为奇数,则为必胜。否则必败。
- 2:无0的情况,奇数边必胜;
- 3:有1的情况。同0的推断一样;
- 4:无1的情况,仅仅剩偶数边的情况,必败;
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 30;
int N, arr[maxn];
bool check (int k) {
int p = -1;
while (arr[++p] != k);
int q = N;
while (arr[--q] != k);
q = N - 1 - q;
return (p&1) || (q&1);
}
bool judge () {
for (int i = 0; i < N; i++) {
if (arr[i] == 0)
return check(0);
}
if (N&1)
return true;
for (int i = 0; i < N; i++) {
if (arr[i] == 1)
return check(1);
}
return false;
}
int main () {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%d", &N);
for (int i = 0; i < N; i++)
scanf("%d", &arr[i]);
printf("%s\n", judge() ? "YES" : "NO");
}
return 0;
}
uva 1561 - Cycle Game(推理)的更多相关文章
- UVA 11090 - Going in Cycle!!(Bellman-Ford)
UVA 11090 - Going in Cycle!! option=com_onlinejudge&Itemid=8&page=show_problem&category= ...
- UVA - 11090 - Going in Cycle!!(二分+差分约束系统)
Problem UVA - 11090 - Going in Cycle!! Time Limit: 3000 mSec Problem Description You are given a we ...
- UVA 11090 Going in Cycle!! SPFA判断负环+二分
原题链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 11246 - K-Multiple Free set(数论推理)
UVA 11246 - K-Multiple Free set 题目链接 题意:一个{1..n}的集合.求一个子集合.使得元素个数最多,而且不存在有两个元素x1 * k = x2,求出最多的元素个数是 ...
- UVA 11090 - Going in Cycle!! SPFA
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa 11090 Going in Cycle!!【Bellman_Ford】
题意:给出n个点m条边的加权有向图,求平均值最小的回路 自己想的是用DFS找环(真是too young),在比较找到各个环的平均权值,可是代码实现不了,觉得又不太对 后来看书= =好巧妙的办法, 使用 ...
- UVA 11090 Going in Cycle!!(二分答案+判负环)
在加权有向图中求平均权值最小的回路. 一上手没有思路,看到“回路”,第一想法就是找连通分量,可又是加权图,没什么好思路,那就转换题意:由求回路权值->判负环,求最小值->常用二分答案. 二 ...
- UVA 11090 Going in Cycle!! 环平均权值(bellman-ford,spfa,二分)
题意: 给定一个n个点m条边的带权有向图,求平均权值最小的回路的平均权值? 思路: 首先,图中得有环的存在才有解,其次再解决这个最小平均权值为多少.一般这种就是二分猜平均权值了,因为环在哪也难以找出来 ...
- UVA 11090 Going in Cycle!!
要求给定的图的中平均权值最小的环,注意处理自环的情况就能过了. 按照w1+w2+w3+….wn < n*ave的不等式,也就是(w1-ave) + (w2-ave) +…..(wn-ave) & ...
随机推荐
- R包——ggplot2(二)
关于ggplot包(二) 关于ggplot包(二) 标尺(Scale) 从前面可以看到,画图其实就是在做映射,不管是映射到不同的几何对象上,还是映射各种图形属性.在对图形属性进行映射之后,使用标尺可以 ...
- Intellij idea workflow 工作流插件安装
idea提供支持的工作插件名字叫actiBPM,可以在idea中在线安装,但往往会连接不成功安装失败,所以这里提供了硬盘安装的方式: 首先是要去官网下载actiBPM插件,下载地址: http://p ...
- Notes常用事件整理
① ボタンのクリック事件: Sub Click(Source As Button) Dim ws As New NotesUIWorkspace Dim uidoc As NotesUIDo ...
- Linux ---> 监控JVM工具
Linux ---> 监控JVM工具shkingshking 发布时间: 2013/10/10 01:27 阅读: 2642 收藏: 26 点赞: 1 评论: 0 JDK内置工具使用 jps(J ...
- Apache服务无法启动的解决方法
apache服务无法启动的解决方法 在配置apache的时候,把apache安装为服务myweb,用apacheMonitor启动myweb发现无法启动,提示:the requested operat ...
- jasmine note
jasmine 简介 jasmine 是一个测试驱动开发(TDD)测试框架, 一个js测试框架,它不依赖于浏览器.dom或其他js框架 jasmine有十分简洁的语法 使用 从 这里 下载 stant ...
- Azure 网站和通配符域
本文章由Azure 网站团队软件开发工程师Michael Candido 撰写 一些 Web 应用程序需要使用多个子域,在某些情况下还需要动态添加新的子域.例如,一个多租户 Web 应用程序可使 ...
- (Android) ContentProvider 实例
ContentProvider 用于应用程序(Android Application)之间传递数据,包括Insert, update, delete, query. 下面的例子是在两个应用之间传递数据 ...
- Android中自己定义组件和它的属性
好长时间没有更新博客了.本来想积累点有深度的东西发,但一直没有找到非常好的点.所以.写一些基础的东西.就当积累吧. Android开发中难免会用到自己定义的组件.以下以ImageButton为例来介绍 ...
- spring+hibernate基础
把数据库的配置信息写在一个文件中 jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc\:mysql\://localhost\:3306/ ...