Program4_S
来源:互联网 发布:java中的垃圾回收机制 编辑:程序博客网 时间:2024/06/05 07:19
我现在做的是第四专题编号为1019的试题,具体内容没如下所示:
Problem S
Time Limit : 15000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 19 Accepted Submission(s) : 7
23 31 22 31 34 21 23 4
Scenario #1:Suspicious bugs found!Scenario #2:No suspicious bugs found!
简单题意:
给定一系列数对,例如a和b,表示a和bb不是同一种性别,然后不断的给出这样的数对,问有没有性别不对的情况。
解题思路:
编写代码:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAX = 2000;
int pre[MAX+5];
int offset[MAX+5];
bool mark;
void init(int n){
int i;
for(i=1;i<=n;++i){
pre[i] = i;
offset[i] = 0;
}
mark = true;
}
int root(int x){
int px;
if(x!=pre[x]){
px = pre[x];
pre[x] = root(pre[x]);
offset[x] = (offset[px] + offset[x])%2;
}
return pre[x];
}
void merge(int x,int y){
int fx = root(x);
int fy = root(y);
if(fx!=fy){
pre[fx] = fy;
offset[fx] = (1 + offset[y] - offset[x])%2;
}
root(x);
}
int main(){
int t,i,n,m,x,y,k;
scanf("%d",&t);
for(i=1;i<=t;++i){
scanf("%d %d",&n,&m);
init(n);
for(k=1;k<=m;++k){
scanf("%d %d",&x,&y);
if(mark){
merge(x,y);
}
if(offset[x]==offset[y]){
mark = false;
}
}
printf("Scenario #%d:\n",i);
if(mark){
printf("No suspicious bugs found!\n");
}else{
printf("Suspicious bugs found!\n");
}
printf("\n");
}
return 0;
}
- Program4_S
- netty tcp option SO_RCVBUF
- SCU2016-01 M题
- Puppet Master 之 布娃娃的创建
- HDU 2852 KiKi's K-Number (树状数组+二分)
- AIDL使用笔记
- Program4_S
- C++ basic 02: 文件输入和输出
- HTML5的Video标签的属性,方法和事件汇总
- Java使用Collections.sort对一个列表进行自定义排序
- 华为机试题--6.质数因子
- Android 注册页面 设置显示或者隐藏密码 和 点击获取验证码倒计时60s
- Web 基础学习之 用 JS 实现网页版本 计算器
- java多线程系列03
- POJ 3213 PM3 矩阵乘法优化