[hdu5285]wyh2000 and pupil
题目←
二分图判定+贪心
对每个联通块内的黑白点数进行统计,将个数较多的累加到ans1中
需特判两个情况:
1、点数 < 2,此时一定无法分成点数均 >= 1的两组
2、没有边,此刻若按上述方法贪心,会出现第二组个数为零的情况
也就是说m == 0和ans2 == 0只需要判一个就好了
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN = 200000 + 50;
struct edge{int f,t;
}l[MAXN << 1];
int n,m,head[MAXN],nxt[MAXN << 1],tot,cnt1,cnt2,ans1,ans2;
queue <int> q;
bool flag;
int col[MAXN];
void init(int n){tot = 0;flag = false;cnt1 = cnt2 = 0;ans1 = ans2 = 0;while(!q.empty())q.pop();for(int i = 1;i <= n;i ++)head[i] = col[i] = -1;
}
int a,b;
void build(int f,int t){l[++ tot].f = f;l[tot].t = t;nxt[tot] = head[f];head[f] = tot;
}
void bfs(int x){col[x] = true;cnt1 ++;q.push(x);while(!q.empty()){int u = q.front();q.pop();for(int i = head[u];i != -1;i = nxt[i]){int t = l[i].t;if(col[t] == -1){col[t] = !col[u];q.push(t);if(col[t])cnt1 ++;else cnt2 ++;}else if(col[t] == col[u]){flag = true;return;}}}if(cnt1 < cnt2)swap(cnt1,cnt2);ans1 += cnt1;ans2 += cnt2;
}
int T;
int main(){scanf("%d",&T);while(T --){scanf("%d%d",&n,&m);init(n);if(n < 2){ printf("Poor wyh\n");continue; } for(int i = 1;i <= m;i ++){scanf("%d%d",&a,&b);build(a,b);build(b,a);}/*if(!m){printf("%d %d\n",n - 1,1);continue;}*/for(int i = 1;i <= n;i ++){cnt1 = cnt2 = 0;if(col[i] == -1)bfs(i);if(flag == true)break;}if(flag){printf("Poor wyh\n");continue;}if(!ans2)ans2 ++,ans1 --;printf("%d %d\n",ans1,ans2);}return 0;
}
[hdu5285]wyh2000 and pupil相关推荐
- 【hdu5285】wyh2000 and pupil
今天下午的二分图染色给我开启新世界的大门啊2333333 这个题要比刚才的关押罪犯简单,只需要染一遍色就能求出答案 #include<iostream> #include<cstri ...
- Pupil dynamics for iris liveness detection 瞳孔活体检测论文翻译
Pupil dynamics for iris liveness detection Abstract 本文的主要目的是提出一种基于瞳孔动力学的完整的眼睛活性检测方法.这种方法可以作为虹膜识别系统中呈 ...
- 8.14-T1村通网(pupil)
题目大意 要建设一个村庄的网络 有两种操作可选 1.给中国移动交宽带费,直接连网,花费为 A. 2.向另外一座有网的建筑,安装共享网线,花费为 B×两者曼哈顿距离. 题解 显然的最小生成树的题 见一个 ...
- 【视线估计】Realtime and Accurate 3D Eye Gaze Capturewith DCNN-based Iris and Pupil Segmentation
论文发表在 IEEE TRANSACTIONS ON VISUALIZATION AND COMPUTER GRAPHICS期刊上,其工程技术方向为SCI 2区,计算机方向为SCI 1区. 1 本文主 ...
- hdu 3876 A pupil’s problem(简单数学题)
点击打开链接 ps:解二次方程,wrong了一次,x1和x2木有判断大小!!! (1)若b^2-4ac<0,无实数根,有两个复数根:x1=[-b+i√(4ac-b^2)]/(2a ...
- 各种光学仪器成像技术(上)
各种光学仪器成像技术(上) 光学是一门很古老的学科,按照Optics的意思,它主要是研究可见光波段的问题. 光学也是一门很有意思的学科.从把光抽象成射线进行处理(光线光学)到把光纳入电磁波的范围(物理 ...
- JavaScript类——鼠标点击下笑脸变化
2019独角兽企业重金招聘Python工程师标准>>> <!DOCTYPE html> <html> <head> <meta charse ...
- 3年级英语听力测试软件,三年级英语听力测试题.doc
三年级英语听力测试题 三年级英语听力测试题 听录音,选择你所听到的单词,将其序号填入题前的括号内.(35分) ( )1.A.grandmother B.grandfather ( )2.A.USA B ...
- 智能哲学:“学习机器”与“机器学习” ——解读图灵思想中的人工智能
周剑铭,自由学者.研究方向为中西文化比较研究,智能哲学,算法.不确定性和不确定性问题(NP)理论. 柳渝,法国儒勒·凡尔纳公立综合大学计算机(Département Informatique, UFR ...
- poj——2771 Guardian of Decency
poj--2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5916 ...
最新文章
- Git 修改分支的名称(亲测)
- Pytorch 神经网络nn模块
- hdu 4856 Tunnels
- wireshark找不到接口_wireshark网络小故障分析定位
- linux下的各种压缩文件安装介绍
- 【opencv】左右两张图片实现全景拼接
- 在Java中从字符串中删除空格
- Django中FBV和CBV
- 代码调试神器:VS Code 开源新工具!
- 求小于N的正整数中含有1的数字的个数
- js怎么获取扫码枪条码_如何使用JavaScript获取扫码枪扫描得到的条形码
- 车载ECU软件刷新flash driver制作
- 【C语言】飞翔的小鸟游戏
- 牛刀小试-Promise
- python修改微信和支付宝步数
- 一个可以截取其他App素材的办法Visual Studio Code
- Debian下Apache2安装与设置 一 ZT
- OpenNI + OpenCV
- BIOS 与 CPU关系
- 出现错误“subprocess.CalledProcessError: Command ‘[‘ninja‘, ‘-v‘]‘ returned non-zero exit status 1”解决方法