A Bug's Life

Time Limit : 15000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 97   Accepted Submission(s) : 38

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

Background 
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.

Input

The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.

Output

The output for every scenario is a line containing "Scenario #i:", where i is the number of the scenario starting at 1, followed by one line saying either "No suspicious bugs found!" if the experiment is consistent with his assumption about the bugs' sexual behavior, or "Suspicious bugs found!" if Professor Hopper's assumption is definitely wrong.

Sample Input

2
3 3
1 2
2 3
1 3
4 2
1 2
3 4

Sample OutpuScenario #1、

Suspicious bugs foundScenario #2:

No suspicious bugs found!

http://blog.csdn.net/shuangde800/article/details/7974664
这位大佬写的向量偏移非常阅读后这题就非常容易了;
就是他写的方程有点奇怪;
我自己觉得是这样的:
aa->bb=(-delta[a]+d-1+delta[b])%3;
a->b=(delta[a]-delta[b])%3; 这题题意用一组数据来说明吧
1 2;2 3;
1 3
1和2是异性,2和3也是异性,也就是1和3是同性,但是他有将a 和b是异性。出现了bug;
 #include <cstring>
#include<stdio.h>
int p[];
int f[];//i的根节点到i的偏移量
int flag; int findi(int x)
{
if(p[x]==x)
return x;
int t=p[x];
p[x]=findi(p[x]);
f[x]=(f[x]+f[t])%;
return p[x];
}
void unioni(int x,int y)
{
int fx=findi(x);
int fy=findi(y);
p[fx]=fy;
f[fx]=(f[y]-f[x]+)%;
return ;
} int main (){
int t; scanf("%d",&t);
int k=;
while(t--)
{
flag=;
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;++i){
p[i]=i;
f[i]=;
}
int a,b;
while(m--){
scanf("%d%d",&a,&b);
int fa=findi(a);
int fb=findi(b);
if(fa==fb){
if(f[a]==f[b])
flag=;
}
else unioni(a,b);
}
if(flag)
printf("Scenario #%d:\nSuspicious bugs found!\n\n",k++);
else
printf("Scenario #%d:\nNo suspicious bugs found!\n\n",k++);
}
return ;
}

A Bug's Life(向量偏移)的更多相关文章

  1. POJ 2492 A Bug's Life (带权并查集 && 向量偏移)

    题意 : 给你 n 只虫且性别只有公母, 接下来给出 m 个关系, 这 m 个关系中都是代表这两只虫能够交配, 就是默认异性, 问你在给出的关系中有没有与异性交配这一事实相反的, 即同性之间给出了交配 ...

  2. POJ 1182 食物链 (带权并查集 && 向量偏移)

    题意 : 中文题就不说题意了…… 分析 : 通过普通并查集的整理归类, 能够单纯地知道某些元素是否在同一个集合内.但是题目不仅只有种类之分, 还有种类之间的关系, 即同类以及吃与被吃, 而且重点是题目 ...

  3. Unity3D学习笔记(三十七):顶点偏移和溶解

    顶点偏移 沿向量方向偏移,沿自身坐标系方向偏移 沿法线方向偏移,球体放大,立方体拆分 Shader "Lesson/VFVertOffsetVertex" { Properties ...

  4. 百度地图 api bug 解决.......

    百度地图 遇到了一个默明奇妙的bug.....  调用后中心点 不再 point(标注的点上...)这是需要执行一次(仅一次) 当 地图 加载完后 执行(这个方法你每次改地图 都会执行...所以让他执 ...

  5. Processing 网格(棋盘格)无限偏移纹理动画

    过火 再度出击!这次我们要玩得更火一点---把静帧变动画.没错,将棋盘格动起来!看一下效果: 这是一个经典的无限偏移动画,在很多2d横版射击游戏中都会采用的技术.如何在Processing中实现,有两 ...

  6. RDD:基于内存的集群计算容错抽象(转)

    原文:http://shiyanjun.cn/archives/744.html 该论文来自Berkeley实验室,英文标题为:Resilient Distributed Datasets: A Fa ...

  7. RDD:基于内存的集群计算容错抽象

    转载自:http://shiyanjun.cn/archives/744.html 摘要 本文提出了分布式内存抽象的概念--弹性分布式数据集(RDD,Resilient Distributed Dat ...

  8. hdu 1829(继续扩展并查集)

    A Bug's Life Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  9. kuangbin带你飞 并查集 题解

    做这套题之前一直以为并查集是很简单的数据结构. 做了才发现自己理解太不深刻.只看重片面的合并集合.. 重要的时发现每个集合的点与这个根的关系,这个关系可以做太多事情了. 题解: POJ 2236 Wi ...

随机推荐

  1. HDU 3526 Computer Assembling(最小割)

    http://acm.hdu.edu.cn/showproblem.php?pid=3526 题意:有个屌丝要配置电脑,现在有n个配件需要购买,有两家公司出售这n个配件,还有m个条件是如果配件x和配件 ...

  2. Tomcat 跨域问题的解决

    先下载CORS对应的Jar: 下载链接: https://download.csdn.net/download/u010739157/10565169 在tomcat的Web.xml中加上如下配置: ...

  3. springboot集成logback日志

    简介 spring boot内部使用Commons Logging来记录日志,但也保留外部接口可以让一些日志框架来进行实现,例如Java Util Logging,Log4J2还有Logback. 如 ...

  4. vs里32位项目和64位项目的区别

    由于操作系统内存分配的不同,导致软件开发过程中,需要编译不同版本的软件. 1.编译程序根据需要选择不同的编译环境. x86和win32为32位程序,x64为64位程序,可以选择不同的编译条件形成不同位 ...

  5. 【Python】一些练习代码用的图片

  6. 在用node安装某个全局模块的时候,没有权限修改node_modules

    一.问题 今天在安装公司内部的一个npm模块的时候,发现报错了⬇ 第一行错误: deprecated graceful-fs@1.2.3: please upgrade to graceful-fs ...

  7. 启动总是提示:Process finished with exit code 0

    1.端口冲突检查端口号 2.缺少web启动依赖 <dependency> <groupId>org.springframework.boot</groupId> & ...

  8. django会话session

    因为因特网HTTP协议的特性,每一次来自于用户浏览器的请求(request)都是无状态的.独立的.通俗地说,就是无法保存用户状态,后台服务器根本就不知道当前请求和以前及以后请求是否来自同一用户.对于静 ...

  9. Token和SessionStorage(会话存储对象)

    sessionStorage数据只在当前标签页共享 存在本地   关闭浏览器后会清除数据(关闭标签页不会清楚) localStorage数据会存在浏览器中  浏览器关了数据也还在 只有清除缓存才会消失 ...

  10. 响应式布局与bootstrap框架

    原文 网页布局方式 1.固定宽度布局:为网页设置一个固定的宽度,通常以px做为长度单位,常见于PC端网页. 2.流式布局:为网页设置一个相对的宽度,通常以百分比做为长度单位. 3.栅格化布局:将网页宽 ...