(简单) POJ 2492 A Bug's Life,二分染色。
Description
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
Problem
Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.
判断奇环,二分染色bfs,并查集都可做。
代码如下:
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月17日 星期五 20时49分42秒
// File Name : 2492.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int map1[MaxN][MaxN];
int flag=;
int vis[MaxN];
int N;
int que[MaxN],first,last; bool bfs(int u)
{
int v; first=last=;
que[last++]=u;
vis[u]=; while(last-first)
{
u=que[first++]; for(v=;v<=N;++v)
if(map1[u][v]==flag && v!=u)
{
if(vis[v]==vis[u])
return ; if(!vis[v])
{
vis[v]=-vis[u];
que[last++]=v;
}
}
} return ;
} bool getans()
{
memset(vis,,sizeof(vis));
first=last=; for(int i=;i<=N;++i)
if(!vis[i])
if(bfs(i))
return ; return ;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int T,cas=;
int Q;
int a,b; scanf("%d",&T); while(T--)
{
scanf("%d %d",&N,&Q);
++flag; while(Q--)
{
scanf("%d %d",&a,&b);
map1[a][b]=map1[b][a]=flag;
} printf("Scenario #%d:\n",cas++); if(getans())
puts("Suspicious bugs found!\n");
else
puts("No suspicious bugs found!\n");
} return ;
}
(简单) POJ 2492 A Bug's Life,二分染色。的更多相关文章
- poj 2492 A Bug's Life 二分图染色 || 种类并查集
		
题目链接 题意 有一种\(bug\),所有的交往只在异性间发生.现给出所有的交往列表,问是否有可疑的\(bug\)(进行同性交往). 思路 法一:种类并查集 参考:https://www.2cto.c ...
 - poj 2492 a bug's life 简单带权并查集
		
题意大致为找同性恋的虫子.... 这个比食物链要简单些.思路完全一致,利用取余操作实现关系之间的递推. 个人感觉利用向量,模和投影可能可以实现具有更加复杂关系的并查集. #include<ios ...
 - hdu - 1829 A Bug's Life (并查集)&&poj - 2492  A Bug's Life && poj 1703 Find them, Catch them
		
http://acm.hdu.edu.cn/showproblem.php?pid=1829 http://poj.org/problem?id=2492 臭虫有两种性别,并且只有异性相吸,给定n条臭 ...
 - POJ 2492 A Bug's Life(并查集)
		
http://poj.org/problem?id=2492 题意 :就是给你n条虫子,m对关系,每一对关系的双方都是异性的,让你找出有没有是同性恋的. 思路 :这个题跟POJ1703其实差不多,也是 ...
 - POJ 2492 A Bug's Life(带权并查集)
		
题目链接:http://poj.org/problem?id=2492 题目大意:有n只虫子,m对关系,m行每行有x y两个编号的虫子,告诉你每对x和y都为异性,先说的是对的,如果后面给出关系与前面的 ...
 - POJ 2492 A Bug's Life (带权并查集 && 向量偏移)
		
题意 : 给你 n 只虫且性别只有公母, 接下来给出 m 个关系, 这 m 个关系中都是代表这两只虫能够交配, 就是默认异性, 问你在给出的关系中有没有与异性交配这一事实相反的, 即同性之间给出了交配 ...
 - POJ 2492 A Bug's Life
		
传送门:A Bug's Life Description Background Professor Hopper is researching the sexual behavior of a rar ...
 - POJ 2492 A Bug's Life (并查集)
		
A Bug's Life Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 30130 Accepted: 9869 De ...
 - POJ 2492 A Bug's Life (并查集)
		
Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes ...
 
随机推荐
- Linux系统查看有几块硬盘
			
使用df命令即可查看.df 是来自于coreutils 软件包,系统安装时,就自带的:我们通过这个命令可以查看磁盘的使用情况以及文件系统被挂载的位置: 示例:[root@localhost ~]# d ...
 - 转 Windows 7设置定时自动执行任务方法
			
在使用电脑的时候可能会遇到一些需要无人值守让电脑自行执行任务后定时关机的情形,在Win7系统中,我们可以使用"任务计划"设置功能结合 shutdown命令灵活设置任务计划,让Win ...
 - php 图片压缩处理
			
<?php require dirname(__FILE__).'/../includes/common.inc.php'; $_clean = array(); $_info = array( ...
 - Java R&W Related
			
In Java, byte = 8 bit, char = 16 bit In C/C++, char = 8 bit There is difference because Java uses Un ...
 - NSUserDefault -- synchronize 浅析
			
NSUserDefault的使用比较简单:NSUserDefaults *mySettingData = [NSUserDefaults standardUserDefaults]; 创建NSUse ...
 - BinTools 十六进制转换
			
package de.rtner.misc; public class BinTools { public static final String hex = "0123456789ABCD ...
 - std::function 测试
			
#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__ #include "cocos2d.h" typedef ...
 - android webview处理下载内容
			
url = "http://m.mumayi.com/"; WebView = (WebView) findViewById(R.id.webView1); WebView.get ...
 - HDU 2668 Daydream
			
用一个队列来维护 每次加入一个字符,如果字符没有在队列里,那么直接入队,并且检查更新队列大小. 如果加入的字符在队列里了,那么要一直弹出队首,直到弹出的字符和当前要插入的一样. #include< ...
 - 用phpstudy搭建dedecms网站验证码出不来解决方案
			
验证码图片不显示,这应该是很多站长朋友们最长遇到的一个问题,本地测试明明好好的,为什么传上空间或者服务器上验证码就无法显示了呢,春哥分析这可能是由于没有加载gd库扩展所引起的,那么怎么解决呢?由于引起 ...