Wrestling Match

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2539    Accepted Submission(s): 922

Problem Description
Nowadays, at least one wrestling match is held every year in our country. There are a lot of people in the game is "good player”, the rest is "bad player”. Now, Xiao Ming is referee of the wrestling match and he has a list of the matches in his hand. At the same time, he knows some people are good players,some are bad players. He believes that every game is a battle between the good and the bad player. Now he wants to know whether all the people can be divided into "good player" and "bad player".
 
Input
Input contains multiple sets of data.For each set of data,there are four numbers in the first line:N (1 ≤ N≤ 1000)、M(1 ≤M ≤ 10000)、X,Y(X+Y≤N ),in order to show the number of players(numbered 1toN ),the number of matches,the number of known "good players" and the number of known "bad players".In the next M lines,Each line has two numbersa, b(a≠b) ,said there is a game between a and b .The next line has X different numbers.Each number is known as a "good player" number.The last line contains Y different numbers.Each number represents a known "bad player" number.Data guarantees there will not be a player number is a good player and also a bad player.
 
Output
If all the people can be divided into "good players" and "bad players”, output "YES", otherwise output "NO".
 
Sample Input
5 4 0 0
1 3
1 4
3 5
4 5
5 4 1 0
1 3
1 4
3 5
4 5
2
 
Sample Output
NO
YES
虽说是道水题但是能够一遍过还是挺爽的。
 
题意:有n个选手,m场比赛,x个著名好选手,y个著名坏选手,每场比赛都是一名号选手与一名坏选手对打。问在这些条件下是否让所有的选手都拥有身份。(非好即坏
 
解题思路:当时想的就是搜索,先把与x相关的搜一遍,确认关系,再把与y相关的搜一遍,最后剩下都不相关的看是否有比赛,如果有比赛,随机设1名为好选手,搜索和他相关的选手,直到所有的比赛都遍历完。
 
ac代码:
  1 #include <cstdio>
2 #include <iostream>
3 #include <cmath>
4 #include <cstring>
5 #include <algorithm>
6 #define ll long long
7 const int maxn = 1000+10;
8 using namespace std;
9 int mp[maxn][maxn];
10 int vis[maxn];
11 int n,m,x,y;
12
13 int ed=0; //ed==1的时候,说明该选手没有比赛,ed==2的时候,说明遇到两个同类型的选手在一起比赛,直接f=1,输出NO
14 void df(int a,int s)
15 {
16 int i=1;
17 if(ed) return;
18 for(i=1;i<=n;++i)
19 {
20 if(mp[a][i] && vis[i]!=s && vis[i]!=0)
21 {
22 ed=2;
23 // printf("\n%d %d\n",a,i);
24 break;
25 }
26 if(mp[a][i] && !vis[i])
27 {
28 vis[i]=s;
29 if(s==1)
30 df(i,2);
31 else
32 df(i,1);
33 }
34 }
35 if(i==n+1)
36 {
37 ed=1;
38 return;
39 }
40 }
41 int main() {
42
43 while(~scanf("%d%d%d%d",&n,&m,&x,&y))
44 {
45 memset(mp,0,sizeof(mp));
46 memset(vis,0,sizeof(vis));
47 int a,b;
48 for(int i=0;i<m;++i)
49 {
50 scanf("%d%d",&a,&b);
51 mp[a][b]=1;
52 mp[b][a]=1;
53 }
54
55 int f=0;
56
57 for(int i=0;i<x;++i)
58 {
59 scanf("%d",&a);
60 vis[a]=1;
61 ed=0;
62 df(a,2);
63 }
64
65 if(ed==2) f=1;
66
67 for(int i=0;i<y;++i)
68 {
69 scanf("%d",&b);
70 vis[b]=2;
71 ed=0;
72 df(b,1);
73 }
74
75 if(ed==2) f=1;
76
77 for(int i=1;i<=n;++i)
78 {
79 for(int j=1;j<=n;++j)
80 {
81 ed=0;
82 if(mp[i][j] && vis[i]==0 && vis[j]==0)
83 {
84 vis[i]=1;
85 df(i,2);
86 }
87 }
88 }
89
90 for(int i=1;i<=n;++i)
91 {
92 if(vis[i]==0)
93 {
94 f=1;
95 break;
96 }
97 }
98 if(!f)
99 printf("YES\n");
100 else
101 printf("NO\n");
102 }
103 return 0;
104 }

hdoj 5971的更多相关文章

  1. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  4. HDOJ 1004 Let the Balloon Rise

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  5. hdoj 1385Minimum Transport Cost

    卧槽....最近刷的cf上有最短路,本来想拿这题复习一下.... 题意就是在输出最短路的情况下,经过每个节点会增加税收,另外要字典序输出,注意a到b和b到a的权值不同 然后就是处理字典序的问题,当松弛 ...

  6. HDOJ(2056)&HDOJ(1086)

    Rectangles    HDOJ(2056) http://acm.hdu.edu.cn/showproblem.php?pid=2056 题目描述:给2条线段,分别构成2个矩形,求2个矩形相交面 ...

  7. 继续node爬虫 — 百行代码自制自动AC机器人日解千题攻占HDOJ

    前言 不说话,先猛戳 Ranklist 看我排名. 这是用 node 自动刷题大概半天的 "战绩",本文就来为大家简单讲解下如何用 node 做一个 "自动AC机&quo ...

  8. 最近点对问题 POJ 3714 Raid && HDOJ 1007 Quoit Design

    题意:有n个点,问其中某一对点的距离最小是多少 分析:分治法解决问题:先按照x坐标排序,求解(left, mid)和(mid+1, right)范围的最小值,然后类似区间合并,分离mid左右的点也求最 ...

  9. BFS(八数码) POJ 1077 || HDOJ 1043 Eight

    题目传送门1 2 题意:从无序到有序移动的方案,即最后成1 2 3 4 5 6 7 8 0 分析:八数码经典问题.POJ是一次,HDOJ是多次.因为康托展开还不会,也写不了什么,HDOJ需要从最后的状 ...

随机推荐

  1. CMU数据库(15-445)Lab1-BufferPoolManager

    0. 关于环境搭建请看 https://www.cnblogs.com/JayL-zxl/p/14307260.html 1. Task1 LRU REPLACEMENT POLICY 0. 任务描述 ...

  2. Nacos 服务配置中心

    1.因为项目是微服务分布式项目,每个微服务都需要用到配置中心,所以第一步我们先在common中添加相应的依赖 <dependency> <groupId>com.alibaba ...

  3. Git 创建新分支检查分支

    创建分支和切换分支,也可以称为检出分支 创建新分支 git branch branchName 切换到新分支 git checkout branchName 上面两个命令也可以合成为一个命令: git ...

  4. 【Soul源码探秘】插件链实现

    引言 插件是 Soul 的灵魂. Soul 使用了插件化设计思想,实现了插件的热插拔,且极易扩展.内置丰富的插件支持,鉴权,限流,熔断,防火墙等等. Soul 是如何实现插件化设计的呢? 一切还得从插 ...

  5. 找出10000内的素数 CSP

    "Problem: To print in ascending order all primes less than 10000. Use an array of processes, SI ...

  6. python_3 装饰器之初次见面

    装饰器 定义:本质是函数,(只不过是用来装饰其他函数而已),就是为其他函数添加附加功能 原则: 1. 不能修改被修饰函数的源代码 2.不能修改被修饰函数的调用方式 实现装饰器的知识储备 1.函数即&q ...

  7. (009)每日SQL学习:Oracle各个键说明(转)

    原文地址:http://www.agiledata.org/essays/keys.html 本文概述关系数据库中为表指定主键的策略.主要关注于何时使用自然键或者代理键的问题.有些人会告诉你应该总是使 ...

  8. Springboot中mybatis控制台打印sql语句

    Springboot中mybatis控制台打印sql语句 https://www.jianshu.com/p/3cfe5f6e9174 https://www.jianshu.com/go-wild? ...

  9. macro-name replacement-text 宏 调试开关可以使用一个宏来实现 do { } while(0)

    C++ 预处理器_w3cschool https://www.w3cschool.cn/cpp/cpp-preprocessor.html C++ 预处理器 预处理器是一些指令,指示编译器在实际编译之 ...

  10. <script>元素

    简介 向HTML页面中插入JavaScript的主要方法,就是使用'<'script'>'元素. 标签的位置 现代Web应用程序一般都把全部的JavaScript饮用放在'<'bod ...