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 ...
随机推荐
- spark之combineByKey
combineByKey def combineByKey[C](createCombiner: (V) => C, mergeValue: (C, V) => C, mergeCombi ...
- Bootstrap 进度条媒体对象和条组
列表组组件 列表组组件用于显示一组列表的组件. //基本实例 <ul class="list-group"> <li class="list-group ...
- mysql select 练习题
10. 查询Score表中的最高分的学生学号和课程号.(子查询或者排序) select sno,cno from score where degree in(select max(degree) f ...
- ecshop insert用法
1 {insert name='ads' id=$ads_id num=$ads_num} 控制语句是在 /includes/lib_insert.php 文件.这个文件是ecshop动态内容函数库. ...
- Servlet Threading Model
Servlet Threading Model The scalability issues of Java servlets are caused mainly by the server thre ...
- 【Android开发学习笔记】【随笔】UI线程
概念 UI线程 是Android中的主线程,涉及到UI方面的一些操作都需要在ui线程中进行操作 在非ui线程中想操作ui,就会报错 android.view.ViewRoot$CalledFromWr ...
- ASP.NET MVC4中用 BundleCollection使用问题手记
ASP.NET MVC4中对JS和CSS的引用又做了一次变化,在MVC3中我们这样引用资源文件: <link href="@Url.Content("~/Content/Si ...
- [LeetCode] Substring with Concatenation of All Words(good)
You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...
- python入门 2014-3-21
刚吃完饭,写一会python 准备去上课,哇咔咔! 1.python是动态类型语言,也就是说 不需要预先声明变量的类型. 不支持 自增++ , 自减--
- Function---hdu5875(大连网选,区间连续求余)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5875 题意:有n个数,m个查询,每个查询有一个区间[L, R], 求ans, ans = ...