HDU 4751 Divide Groups
来源:互联网 发布:通过js获取网页源代码 编辑:程序博客网 时间:2024/05/17 23:30
HDU 4751 Divide Groups
题目链接:HDU 4751 Divide Groups
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.
Output
If divided successfully, please output “YES” in a line, else output “NO”.
Sample Input
3
3 0
1 0
1 2 0
Sample Output
YES
题意:
将n个人分到两个集合中,要求每个集合中的人都相互认识
AC代码:
#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#include <algorithm>#include <iostream>#include <locale>#include <vector>#include <string>#include <iomanip>#include <cstdio>#include <cstring>#include <stack>#include <queue>#include <map>#include <set>#include <functional>using namespace std;int group[105][105];int qun[105];int n;bool panduan(int now){ queue<int> que; que.push(now); int pos; while(!que.empty()) { pos=que.front(); que.pop(); for(int i=1;i<=n;i++) { if(i==pos||(group[i][pos]&&group[pos][i])) continue; else if(qun[i]==-1) { qun[i]=qun[pos]^1; que.push(i); } else if(qun[i]==qun[pos]) return false; } } return true;}int main(){ while(~scanf("%d",&n)) { memset(group,0,sizeof group); memset(qun,-1,sizeof qun); int flag=1; for(int i=1; i<=n; i++) { int j; while(scanf("%d",&j),j) group[i][j]=1; } for(int i=1; i<=n; i++) { if(qun[i]==-1) { qun[i]=0; if(!panduan(i)) { flag=0; break; } } } if(flag) printf("YES\n"); else printf("NO\n"); } return 0;}
- 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
- hdu 4751——Divide Groups
- HDU 4751 Divide Groups (BFS)
- HDU-#4751 Divide Groups(2-SAT)
- HDU 4751 Divide Groups (二分图)
- HDU - 4751 Divide Groups(二分图)
- hdu 4751 Divide Groups (二分图判断)
- HDU 4751 Divide Groups 二分图判断
- HDU 4751 Divide Groups(二分图判断)
- OpenJudge百炼-2787-算24-C语言-枚举
- 欢迎使用CSDN-markdown编辑器
- 05-Mac下面使用HomeBrew安装mongodb数据库
- 第一章 初识java
- 【Tensorflow入门】手写字体识别(MNIST)
- HDU 4751 Divide Groups
- 一句话描述插入排序和选择排序的区别
- centos增加swap空间
- android通过友盟进行微信分享的坑
- 数据预处理
- Kotlin 实现Activity之间的跳转 和 布局控件的简单调用
- Spinnaker 核心概念解析
- java.io包
- 数据结构与算法专题之查找与排序——插入类排序(插入、希尔)