HDU5971【瞎搞】
题意:略(忙着准备文化课。。。明天期中考啊。。。。
思路:
正解就是染色,2-sat搞;
AC代码(虽然是错误的。。。数据水(过踏马的也行啊,起码打脸他啊!)
4 3 1 0
1 2
2 3
3 4
4
这个就挂了;
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX=1010;
const double q=(1+sqrt(5.0))/2.0;
const double eps=1e-100;
int n,m;
int v[MAX];
int a[MAX][MAX];
int main()
{
int t,i,j;
int x,y;
while(~scanf("%d%d%d%d",&n,&m,&x,&y))
{
int flag=0;
int b,c;
memset(a,0,sizeof(a));
memset(v,-1,sizeof(v));
for(i=0;i<m;i++)
{
scanf("%d%d",&b,&c);
a[b][c]=a[c][b]=1;
}
for(i=1;i<=x;i++)
{
scanf("%d",&b);
for(j=0;j<n;j++)
{
if(a[b][j])
{
if(v[j]==1)
flag=1;
v[j]=0;
}
}
v[b]=1;
}
for(i=1;i<=y;i++)
{
scanf("%d",&b);
for(j=0;j<n;j++)
{
if(a[b][j])
{
if(v[j]==0)
flag=1;
v[j]=1;
}
}
v[b]=0;
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
if(a[i][j])
{
if(v[i]==-1&&v[j]==-1)
{
v[i]=1;
v[j]=0;
}
else if(v[i]!=-1&&v[j]!=-1)
{
if(v[i]+v[j]!=1)
flag=1;
}
else if(v[i]!=-1)
{
v[j]=1-v[i];
}
else
v[i]=1-v[j];
}
}
}
for(i=1;i<=n;i++)
{
// printf("%d ",v[i]);
if(v[i]==-1)
flag=1;
}
// puts("");
if(flag)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
贴份应该正确的(escape
#include<bits/stdc++.h>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int N=5*1e4+1000;
#define eps 1e-4
int co[10005];
int vis[10005];
vector<int>g[10005];
int dfs(int u)
{
int sz=g[u].size();
for(int i=0; i<sz; i++)
{
int v=g[u][i];
if(!co[v])
{
co[v]=!co[u];
if(!dfs(v))
return 0;
}
else if(co[u]==co[v])
{
return 0;
}
}
return 1;
}
int main()
{
int n,m,x,y;
while(cin>>n>>m>>x>>y)
{
for(int i=0; i<10005; i++)
g[i].clear();
if(n==1)
{
puts("NO");
continue;
}
for(int i=0; i<m; i++)
{
int xx,yy;
scanf("%d%d",&xx,&yy);
g[xx].push_back(yy);
}
memset(co,0,sizeof(co));
for(int i=0; i<x; i++)
{
int xx;
scanf("%d",&xx);
co[xx]=1;
// int sz=g[xx].size();
// for(int i=0; i<sz; i++)
// {
// int v=g[xx][i];
// co[v]=!co[xx];
// }
}
for(int i=0; i<y; i++)
{
int xx;
scanf("%d",&xx);
co[xx]=0;
// int sz=g[xx].size();
// for(int i=0; i<sz; i++)
// {
// int v=g[xx][i];
// co[v]=!co[xx];
// }
}
if(x==0&&y==0)
puts("NO");
else
{
int flag=1;
for(int i=1; i<=n; i++)
if(!dfs(i))
flag=0;
if(flag)
puts("YES");
else
puts("NO");
}
}
return 0;
}
加强后的瞎搞(求hack
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX=1010;
const double q=(1+sqrt(5.0))/2.0;
const double eps=1e-100;
int n,m;
int v[MAX];
int a[MAX][MAX];
int main()
{
int t,i,j,k;
int x,y;
while(~scanf("%d%d%d%d",&n,&m,&x,&y))
{
int flag=0;
int b,c;
memset(a,0,sizeof(a));
memset(v,-1,sizeof(v));
for(i=0; i<m; i++)
{
scanf("%d%d",&b,&c);
a[b][c]=a[c][b]=1;
}
for(i=1; i<=x; i++)
{
scanf("%d",&b);
for(j=0; j<n; j++)
{
if(a[b][j])
{
if(v[j]==1)
flag=1;
v[j]=0;
}
}
v[b]=1;
}
for(i=1; i<=y; i++)
{
scanf("%d",&b);
for(j=0; j<n; j++)
{
if(a[b][j])
{
if(v[j]==0)
flag=1;
v[j]=1;
}
}
v[b]=0;
}
for(k=0; k<2; k++)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
if(a[i][j])
{
if(v[i]==-1&&v[j]==-1&&k)
{
v[i]=1;
v[j]=0;
}
else if(v[i]!=-1&&v[j]!=-1)
{
if(v[i]+v[j]!=1)
flag=1;
}
else if(v[i]!=-1)
{
v[j]=1-v[i];
}
else if(v[j]!=-1)
v[i]=1-v[j];
}
}
}
}
for(i=1; i<=n; i++)
{
// printf("%d ",v[i]);
if(v[i]==-1)
flag=1;
}
// puts("");
if(flag)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
/*
6 5 0 0
1 2
2 3
3 4
3 1
5 6 6 5 0 0
1 2
2 3
3 4
4 1
5 6 4 3 1 0
1 2
2 3
3 4
4 */
HDU5971【瞎搞】的更多相关文章
- URAL 1203. Scientific Conference(瞎搞)
题目链接 本来觉得这不是经典的贪心吗..果断水一次,wa了,看了看discuss,发现貌似不好水,土土的DP了一下,复杂度很高了,又T了...然后想想单调队列,二分什么的...不好往上加,直接搞了标记 ...
- Codeforces Gym 100610 Problem H. Horrible Truth 瞎搞
Problem H. Horrible Truth Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1006 ...
- B. Salty Fish Go! -期望题(瞎搞题)
链接:https://www.nowcoder.com/acm/contest/104/B来源:牛客网 题意:A few days ago, WRD was playing a small game ...
- HDU5532 Almost Sorted Array(最长上升子序列 or 瞎搞个做差的数组)
题目链接:点我 题意:给定一个序列,询问是否能删除一个数让它成为非递减或者非递增的序列. 比如说 删除后的序列是1 3 3 5 或者5 3 3 1 或者1 3 5 或者5 3 1 都可以.只要满足删掉 ...
- TOJ3097: 单词后缀 (字典树 or map瞎搞)
传送门 (<---可以点击的~) 时间限制(普通/Java):1000MS/3000MS 内存限制:65536KByte 描述 有些英语单词后缀都是一样的,现在我们需要从给定的一堆单词里 ...
- 8VC Venture Cup 2016 - Elimination Round B. Cards 瞎搞
B. Cards 题目连接: http://www.codeforces.com/contest/626/problem/B Description Catherine has a deck of n ...
- ubuntu--基础环境瞎搞集合
安装ubuntu系统后有很多东西需要自己瞎搞一下,这里把一些瞎搞的过程记录在这里,方便以后重新装系统后重新配置. 一.安装. 可以在windows下制作启动盘(软碟通),然后开机u盘启动即可安装,预留 ...
- Codeforces631C【栈维护+瞎搞】
题意: 百度. 思路: 如果该查询的R比前面的所有都大,那么前面所有都失效. 那么我先预处理出这些有效的. 那最坏的情况不就是栈里面元素(R)很多 n,n-1,n-2,n-3,n-4而且都是相反排序的 ...
- BZOJ 4236: JOIOJI map瞎搞
分别记录J,O,I,的个数 cnt[char][i] 表示处理到第i位,char的个数 显然当且仅当 cnt[J][i] - cnt[O][i] == cnt[J][j-1] - cnt[O][j-1 ...
随机推荐
- 《UNIX 网络编程 第二版》编译环境的搭建( 运行本专栏代码必读 )
第一步:搭建基本的编译环境 安装gcc, g++, bulid-essential等编译软件 第二步:下载本书示例源码包 可在这里下载http://ishare.iask.sina.com.cn/f/ ...
- 解决Android Studio下Element layer-list must be declared问题
近期将一个项目从Eclipse转到Android Studio. 项目中使用了环信demo中的一些xml资源,转换后发现color资源目录下诸如layer-list或者shape等标签报Element ...
- [学些东西]用爬虫练习网站来练习burp suite
最近看爬虫的内容.刚好看到黑板客爬虫第二关http://www.heibanke.com/lesson/crawler_ex01. ADO的i春秋课程里面提到的.另外推荐学习爬虫的好书<web ...
- 【iOS开发】---- UIView动画
iOS 动画UIView动画 原文:http://www.cocoachina.com/bbs/read.php?tid=110168 1.概述 UIKit直接将动画集成到UIView类中,实现简 ...
- Sping中Bean配置的深入探讨
一.p命名空间的使用 Spring 从 2.5 版本开始引入了一个新的 p 命名空间,可以通过 <bean> 元素属性的方式配置 Bean 的属性.使用 p 命名空间后,基于 XML 的配 ...
- MFC获取电脑硬盘序列号(附源代码)
在新建的project里面加入一个类 即:下面一个类 GetHDSerial.cpp <code class="hljs cs has-numbering" style= ...
- Android Handle,Looper,Message消息机制
尊重原创,转载请标明出处 http://blog.csdn.net/abcdef314159 我们知道在Android中更新UI都是在主线程中,而操作一些耗时的任务则须要在子线程中.假设存在多个 ...
- Leetcode:remove_duplicates_from_sorted_list
一. 题目 给定一个排好序的链表,删除全部反复的节点,使每个节点都仅仅出现一次 比如: Given 1->1->2, return 1->2. Given 1->1-& ...
- CSS阶段总结
CSS布局之左右布局与左中右布局 方法:为子元素设置浮动,然后在其父元素上使用clearfix类来清除浮动.代码示例: html部分: <div class="parent clear ...
- 在Eclipse Java EE编译器中修改Web项目的发布名称
在工程目录上右键, 选properties, 弹出属性窗口, 选中Web Project Settings, 在右边的Context root中修改保存即可 死马当做活马医 在你的工程目录下找到.se ...