C++之路进阶——bzoj2199(奶牛议会)

| F.A.Qs | Home | Discuss | ProblemSet | Status | Ranklist | Contest | ModifyUser gryz2016 | Logout | 捐赠本站 |
|---|
2199: [Usaco2011 Jan]奶牛议会
Time Limit: 10 Sec Memory Limit: 259 MB
Submit: 258 Solved: 162
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
1 Y 2 N
1 N 2 N
1 Y 3 Y
1 Y 2 Y
Sample Output
HINT
Source
题解:
2-set问题,Y和N都考虑一下,最后check一下。
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#define maxn 10000 using namespace std; inline int read()
{
int x=;
char ch=getchar();
while (ch>''||ch<'') ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x;
} int get()
{
int x=read();char c=getchar();
while(c!='Y'&&c!='N')c=getchar();
if(c=='Y')x=x*-;
else x=x*;
return x;
} struct ss
{
int to;
int next;
}e[maxn]; int head[maxn],n,m,ans[maxn],cnt;
bool kg[maxn];
char ch[]={'?','N','Y'};
int insert(int u,int v)
{
e[++cnt].to=v; e[cnt].next=head[u]; head[u]=cnt;
} void dfs(int x)
{
kg[x]=;
for (int i=head[x];i;i=e[i].next)
if (!kg[e[i].to]) dfs(e[i].to);
} bool check(int x)
{
memset(kg,,sizeof(kg));
dfs(x);
for (int i=;i<=n;i++)
if (kg[*i]&&kg[*i-]) return ;
return ;
} int main()
{
n=read();
m=read();
for (int i=;i<=m;i++)
{
int x=get(),xp;
int y=get(),yp;
if (x%==) xp=x--;
else xp=x++;
if (y%==) yp=y--;
else yp=y++;
insert(xp,y);
insert(yp,x);
}
for (int i=;i<=n;i++)
{
bool p=check(*i);
bool q=check(*i-);
if(!p&&!q){printf("IMPOSSIBLE");return ;}
else if(p&&q)ans[i]=;
else if(!p)ans[i]=;
else ans[i]=;
}
for(int i=;i<=n;i++)
printf("%c",ch[ans[i]]);
return ;
}
C++之路进阶——bzoj2199(奶牛议会)的更多相关文章
- BZOJ2199 奶牛议会 【2-sat】
BZOJ2199 奶牛议会 Description 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会.议会以"每头牛 都可以获得自己想要的"为原则, ...
- 【BZOJ2199】[Usaco2011 Jan]奶牛议会 2-SAT
[BZOJ2199][Usaco2011 Jan]奶牛议会 Description 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会.议会以“每头牛 都可以获得自己想要 ...
- 【BZOJ2199】 [Usaco2011 Jan]奶牛议会
Description 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会.议会以“每头牛 都可以获得自己想要的”为原则,建立了下面的投票系统: M只到场的奶牛 (1 & ...
- BZOJ2199: [Usaco2011 Jan]奶牛议会(2-SAT)
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 559 Solved: 360[Submit][Status][Discuss] Descriptio ...
- BZOJ2199[Usaco2011 Jan]奶牛议会——2-SAT+tarjan缩点
题目描述 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会.议会以“每头牛 都可以获得自己想要的”为原则,建立了下面的投票系统: M只到场的奶牛 (1 <= M ...
- BZOJ 2199: [Usaco2011 Jan]奶牛议会
2199: [Usaco2011 Jan]奶牛议会 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 375 Solved: 241[Submit][S ...
- 2-set奶牛议会
Description 由于对Farmer John的领导感到极其不悦,奶牛们退出了农场,组建了奶牛议会.议会以“每头牛 都可以获得自己想要的”为原则,建立了下面的投票系统: M只到场的奶牛 (1 & ...
- 【BZOJ-2199】奶牛议会
链接: BZOJ-2199 题意: 给出 \(n(1\leq n\leq 1000)\) 个点,\(m(1\leq m\leq 4000)\) 个形如:"点 \(a\) 取 \(ca\) 或 ...
- BZOJ2199: [Usaco2011 Jan]奶牛议会
趁此机会学了一下2-SAT. 以前的2-SAT都是用并查集写的,只能应用于极小的一部分情况,这次学了一正式的2-SAT,是用一张有向图来表示其依赖关系. 2-SAT的介绍参见刘汝佳<训练指南&g ...
随机推荐
- 分页查询:使用分页类查询 用get传值
<body> <?php $cx = ""; if(!empty($_GET["cx"])) //判断get传过来的值非空,那么把传过来的值赋 ...
- JS事件分析
1.注册事件 1.1 使用HTML元素的事件属性 <div id='myDiv' style="width:100px;height:100px;background-color:re ...
- 编译mod_jk.so
编译mod_jk.so前,需要先到http://tomcat.apache.org/download-connectors.cgi去下载tomcat-connectors-1.2.41-src.tar ...
- RedHat6.6安装Oracle11gR2
RedHat6.6安装Oracle11gR2 一.Centos6.6的安装配置 1- 选择安装模式 2- 选择“skip”,跳过检查. 3- 选择“下一步” 4- ...
- 英特尔15天开发IDF硬享公社App全过程
4月8日英特尔智能硬件大赛在上海决赛,4月13日英热尔智能硬件大赛10强在深圳首秀.英特尔辗转两大城市来顾全两地智能硬件创业者,移动直播就成了用户们最重要的观看渠道. 这次英特尔两大会事现场直播都在官 ...
- Java Set操作
Set:无顺序,不包含重复的元素 HashSet:为快速查找设计的Set.存入HashSet的对象必须定义hashCode(). TreeSet: 保存次序的Set, 底层为树结构.使用它可以从Set ...
- 第四篇 SQL Server代理配置数据库邮件
本篇文章是SQL Server代理系列的第四篇,详细内容请参考原文. 正如这一系列的前几篇所述,SQL Server代理作业是由一系列的作业步骤组成,每个步骤由一个独立的类型去执行.SQL Serve ...
- Unity3D 插件大全
2D_Toolkit 2d动画开发插件包 FingerGestures 触摸插件 ORK_Okashi_RPG_Kit Unity3D角色扮演游戏开发工具包 uScript-Visual-Script ...
- Win7 OpenCV 3.0.0 VS2013 环境配置
参考资料:http://jingyan.baidu.com/article/75ab0bcbee4b47d6864db2fc.html 注: x86 x64 这些根据自己的系统以及需求而定, 这里就不 ...
- CentOS安装Git
准备安装Gityum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel #下载git-1 ...