HDOJ 4751 Divide Groups
来源:互联网 发布:js 给隐藏的input赋值 编辑:程序博客网 时间:2024/05/14 16:23
染色判断二分图+补图
比赛的时候题意居然是反的,看了半天样例都看不懂 。。。。
Total Submission(s): 456 Accepted Submission(s): 172
This year is the 60th anniversary of NJUST, and to make the celebration more colorful, Tom200 is going to invite distinguished alumnus back to visit and take photos.
After carefully planning, Tom200 announced his activity plan, one that contains two characters:
1. Whether the effect of the event are good or bad has nothing to do with the number of people join in.
2. The more people joining in one activity know each other, the more interesting the activity will be. Therefore, the best state is that, everyone knows each other.
The event appeals to a great number of alumnus, and Tom200 finds that they may not know each other or may just unilaterally recognize others. To improve the activities effects, Tom200 has to divide all those who signed up into groups to take part in the activity at different time. As we know, one's energy is limited, and Tom200 can hold activity twice. Tom200 already knows the relationship of each two person, but he cannot divide them because the number is too large.
Now Tom200 turns to you for help. Given the information, can you tell if it is possible to complete the dividing mission to make the two activity in best state.
比赛的时候题意居然是反的,看了半天样例都看不懂 。。。。
Divide Groups
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 456 Accepted Submission(s): 172
Problem Description
This year is the 60th anniversary of NJUST, and to make the celebration more colorful, Tom200 is going to invite distinguished alumnus back to visit and take photos.
After carefully planning, Tom200 announced his activity plan, one that contains two characters:
1. Whether the effect of the event are good or bad has nothing to do with the number of people join in.
2. The more people joining in one activity know each other, the more interesting the activity will be. Therefore, the best state is that, everyone knows each other.
The event appeals to a great number of alumnus, and Tom200 finds that they may not know each other or may just unilaterally recognize others. To improve the activities effects, Tom200 has to divide all those who signed up into groups to take part in the activity at different time. As we know, one's energy is limited, and Tom200 can hold activity twice. Tom200 already knows the relationship of each two person, but he cannot divide them because the number is too large.
Now Tom200 turns to you for help. Given the information, can you tell if it is possible to complete the dividing mission to make the two activity in best state.
Input
The input contains several test cases, terminated by EOF.
Each case starts with a positive integer n (2<=n<=100), which means the number of people joining in the event.
N lines follow. The i-th line contains some integers which are the id
of students that the i-th student knows, terminated by 0. And the id starts from 1.
Each case starts with a positive integer n (2<=n<=100), which means the number of people joining in the event.
N lines follow. The i-th line contains some integers which are the id
of students that the i-th student knows, terminated by 0. And the id starts from 1.
Output
If divided successfully, please output "YES" in a line, else output "NO".
Sample Input
3
3 0
1 0
1 2 0
3 0
1 0
1 2 0
Sample Output
YES
Source
2013 ACM/ICPC Asia Regional Nanjing Online
Recommend
liuyiding
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
int guanxi[111][111],color[111];
typedef struct
{
int to,next;
}Edge;
Edge E[21000];
int Adj[21000],Size=0;
void Init()
{
Size=0;
memset(Adj,-1,sizeof(Adj));
}
void Add_Edge(int u,int v)
{
E[Size].to=v;
E[Size].next=Adj;
Adj=Size++;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(guanxi,0,sizeof(guanxi));
for(int i=1;i<=n;i++)
{
int x;
while(scanf("%d",&x)&&x)
{
guanxi[x]=1;
}
}
Init();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j) continue;
if(!guanxi[j]||!guanxi[j])
{
Add_Edge(i,j);
// printf("%d---->%d\n",i,j);
}
}
}
memset(color,0,sizeof(color));
bool flag=true;
while(true)
{
if(flag==false) break;
int pos=-1;
for(int i=1;i<=n;i++)
{
if(Adj==-1) continue;
else if(color!=0) continue;
else
{
pos=i;
break;
}
}
// printf("pos: %d\n",pos);
if(pos==-1) break;
queue<int> q;
q.push(pos);color[pos]=1;
while(!q.empty())
{
if(flag==false) break;
int u=q.front(); q.pop();
for(int i=Adj;~i;i=E.next)
{
int v=E.to;
// printf("%d------>%d\n %d %d\n",u,v,color,color[v]);
if(color[v]==0)
{
color[v]=-color;
q.push(v);
}
else if(color[v]==color)
{
flag=false;
break;
}
// printf("%d------>%d\n %d %d\n",u,v,color,color[v]);
}
}
}
if(!flag)
puts("NO");
else
puts("YES");
}
return 0;
}
* This source code was highlighted by YcdoiT. ( style: Codeblocks )#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
int guanxi[111][111],color[111];
typedef struct
{
int to,next;
}Edge;
Edge E[21000];
int Adj[21000],Size=0;
void Init()
{
Size=0;
memset(Adj,-1,sizeof(Adj));
}
void Add_Edge(int u,int v)
{
E[Size].to=v;
E[Size].next=Adj
Adj
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(guanxi,0,sizeof(guanxi));
for(int i=1;i<=n;i++)
{
int x;
while(scanf("%d",&x)&&x)
{
guanxi
}
}
Init();
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==j) continue;
if(!guanxi
{
Add_Edge(i,j);
// printf("%d---->%d\n",i,j);
}
}
}
memset(color,0,sizeof(color));
bool flag=true;
while(true)
{
if(flag==false) break;
int pos=-1;
for(int i=1;i<=n;i++)
{
if(Adj
else if(color
else
{
pos=i;
break;
}
}
// printf("pos: %d\n",pos);
if(pos==-1) break;
queue<int> q;
q.push(pos);color[pos]=1;
while(!q.empty())
{
if(flag==false) break;
int u=q.front(); q.pop();
for(int i=Adj
{
int v=E
// printf("%d------>%d\n %d %d\n",u,v,color
if(color[v]==0)
{
color[v]=-color
q.push(v);
}
else if(color[v]==color
{
flag=false;
break;
}
// printf("%d------>%d\n %d %d\n",u,v,color
}
}
}
if(!flag)
puts("NO");
else
puts("YES");
}
return 0;
}
0 0
- HDOJ 4751 Divide Groups
- HDOJ 4751 - Divide Groups 暴力DFS
- HDOJ-----4751---Divide Groups二分判断
- HDU 4751 Divide Groups
- HDU-4751-Divide Groups
- HDU 4751 Divide Groups
- HDU:4751 Divide Groups
- HDU-4751 Divide Groups
- HDU 4751 Divide Groups
- hdu 4751 Divide Groups
- HDU 4751 Divide Groups
- hdu 4751 Divide Groups 染色
- HDU 4751 — Divide Groups
- HDOJ题目4751 Divide Groups(染色法判二分图)
- Divide Groups
- hdu 4751——Divide Groups
- HDU 4751 Divide Groups (BFS)
- HDU-#4751 Divide Groups(2-SAT)
- ActiveReports 报表应用教程 (2)---清单类报表
- HDOJ 4747 Mex
- ActiveReports 报表应用教程 (3)---图表报表
- HDOJ 4739 Zhuge Liang&#39;s Mines
- ActiveReports 报表应用教程 (4)---分栏报表
- HDOJ 4751 Divide Groups
- ActiveReports 报表应用教程 (5)---解密电子商务领域首张电子发票的诞生(套打报表)
- HDOJ 4750 Count The Pairs
- ActiveReports 报表应用教程 (6)---分组报表
- HDOJ 1711 Number Sequence
- ActiveReports 报表应用教程 (7)---交叉报表及数据透视图实现方案
- POJ 2299 Ultra-QuickSort
- ActiveReports 报表应用教程 (8)---交互式报表之动态过滤
- CSDN下载频道2014年11月4日-5日维护公告
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
时间与日期
日期和时间
结婚 日期
剖腹产日期
算结婚日期
小升初日期
今天的日期
日期 英语
日期的英文
高铁日期
月经日期
日期表
日期章
日期阴历
日期减法
日期提醒
中秋日期
日期间隔
日期天数
日期今天
手机日期
查询日期
日期公式
轮胎生产日期
轮胎生产日期怎么看
信用卡还款日期怎么算
玻璃生产日期
国庆放假日期
轮胎日期怎么看
轮胎看生产日期
日期计算器输入天数计算日期
日期的英语单词
今天日期时间
香蕉船 生产日期
日期间隔计算器
阴历日期计算
香蕉船生产日期
日期计算时间
时间日期显示
时间日期计算器
昂科威上市日期