poj1733Parity game
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7288 | Accepted: 2833 |
Description
You suspect some of your friend's answers may not be correct and you want to convict him of falsehood. Thus you have decided to write a program to help you in this matter. The program will receive a series of your questions together with the answers you have received from your friend. The aim of this program is to find the first answer which is provably wrong, i.e. that there exists a sequence satisfying answers to all the previous questions, but no such sequence satisfies this answer.
Input
Output
Sample Input
10
5
1 2 even
3 4 odd
5 6 even
1 6 even
7 10 odd
Sample Output
3
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX = ;
int a[*MAX],father[*MAX],r[*MAX];
struct Node
{
int u,v;
char str[];
};
Node que[MAX];
int n,m,cnt;
int Bin(int x)
{
int r = cnt - ;
int l = ; while(r >= l)
{
int mid = (r + l) / ;
if(a[mid] > x)
r = mid - ;
else if(a[mid] < x)
l = mid + ;
else
return mid;
}
return -;
}
int find_father(int x)
{
if(father[x] == x)
return x;
int t = find_father(father[x]);
r[x] = r[x] ^ r[father[x]];
return father[x] = t;
}
int main()
{
while(scanf("%d%d",&n,&m) != EOF)
{
cnt = ;
for(int i = ; i <= m; i++)
{
scanf("%d%d%s", &que[i].u,&que[i].v,que[i].str);
que[i].u --;
a[cnt++] = que[i].u;
a[cnt++] = que[i].v;
}
sort(a,a + cnt);
cnt = unique(a,a + cnt) - a;
for(int i = ; i <= cnt; i++)
{
father[i] = i;
r[i] = ;
}
int ans = ;
for(int i = ; i <= m; i++)
{
int x = Bin(que[i].u);
int y = Bin(que[i].v);
int fx = find_father(x);
int fy = find_father(y);
if(fx == fy)
{
if(r[x] == r[y] && strcmp(que[i].str,"odd") == )
break;
if(r[x] != r[y] && strcmp(que[i].str,"even") == )
break;
ans++;
}
else
{
if(strcmp(que[i].str,"odd") == )
{
father[fx] = fy;
r[fx] = r[x]^ ^ r[y];
}
else
{
father[fy] = fx;
r[fy] = r[x] ^ r[y] ^ ;
}
ans ++;
}
}
printf("%d\n",ans);
} return ;
}
poj1733Parity game的更多相关文章
随机推荐
- CSS3弹性伸缩布局(一)——box布局
CSS3弹性伸缩布局简介 2009年,W3C提出了一种崭新的方案----Flex布局(即弹性伸缩布局),它可以简便.完整.响应式地实现各种页面布局,包括一直让人很头疼的垂直水平居中也变得很简单地就迎刃 ...
- vuejs使用技巧
组件创建自定义标签时,自定义的标签不要用驼峰写法,vue否者报错,例如<my-template></my-template>合法或者去掉中间的斜杠全部小写,只要出现大写字母就会 ...
- RDLC报表系列--------行分组报表
报表分组开发步骤: 先看总体效果:如图 下面就做个看看... 1.先将数据处理成如下结构 如图 2.创建数据集DataSet.xsd,创建表->右键选择添加数据表->添加行(ctrl+L ...
- TinyFrame升级之二:数据底层访问部分
在上一篇中,我列举了框架的整体结构,下面我们将一一说明: 首先需要说明的是TinyFrame.Data. 它主要用于处理数据库底层操作.包含EF CodeFirst,Repository,Unitof ...
- linux内核分析 第4章读书笔记
第四章 进程调度 一.抢占与非抢占 1.非抢占式进程调度 进程会一直执行直到自己主动停止运行 2.抢占式进程调度 Linux/Unix使用的是抢占式的方式,强制的挂起进程的动作就叫做抢占. 二.进程优 ...
- MVC5 + EF6 + Bootstrap3 (9) HtmlHelper用法大全(下)
文章来源:Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc5-ef6-bs3-get-started-httphelper-part2.html 上一节 ...
- 一个基于.NET平台的自动化/压力测试系统设计简述
AutoTest系统设计概述 AutoTest是一个基于.NET平台实现的自动化/压力测试的系统,可独立运行于windows平台下,支持分布式部署,不需要其他配置或编译器的支持.(本质是一个基于协议的 ...
- unity3d 赛车游戏——复位点检测优化、反向检测、圈数检测、赛道长度计算
接着上一篇文章说 因为代码简短且思路简单 所以我就把这几个功能汇总为一篇文章 因为我之前就是做游戏外挂的 经过验证核实,**飞车的复位点检测.圈数检测就是以下的方法实现的 至于反向检测和赛道长度计算, ...
- iOS 后台运行 类型
iOS后台运行,需要有特定的类型才可以进行.这些内容并不是一直不变的,苹果也在逐步的更新这些内容. 本文内容是2015年11月03日时苹果支持的后台运行类型. 这是官方连接地址 其中较为重要的是下面这 ...
- Android Studio导入Eclipse项目和一些常见的问题
Android Studio版本 Eclipse项目工程:一个主工程,一个Emojicon依赖库. 有两种方式导入Eclipse工程: 1.兼容Eclipse 2.全新的Android Gradle ...