北京大学ACM-ICPC竞赛训练暑期课 / 练习 028:A Bug‘s Life

028:A Bug’s Life

总时间限制: 10000ms
内存限制: 65536kB

描述

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.

输入

  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.

输出

  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.

样例输入

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

样例输出

Scenario #1:
Suspicious bugs found!

Scenario #2:
No suspicious bugs found!

提示

Huge input,scanf is recommended.

来源

TUD Programming Contest 2005, Darmstadt, Germany


        查看      提交      统计      提问


我的提交记录

  如果你看到了一个交了那么多次傻子,没错,是我,为啥,因为我想交一个可以循环输入的程序,这道题不允许,这道题如果你交一个可以循环输入的WA,欢迎您!!

#	     结果                	时间
37	Accepted	            2020-08-27
36	Accepted	            2020-08-27
35	Accepted	            2020-08-27
34	Compile Error	        2020-08-27
33	Accepted	            2020-08-27
32	Wrong Answer	        2020-08-27
31	Wrong Answer	        2020-08-27
30	Wrong Answer	        2020-08-27
29	Wrong Answer	        2020-08-27
28	Compile Error	        2020-08-27
27	Wrong Answer	        2020-08-27
26	Wrong Answer	        2020-08-27
25	Wrong Answer	        2020-08-27
24	Wrong Answer	        2020-08-27
23	Wrong Answer	        2020-08-27
22	Wrong Answer	        2020-08-27
21	Compile Error	        2020-08-27
20	Wrong Answer	        2020-08-27
19	Wrong Answer	        2020-08-27
18	Wrong Answer	        2020-08-27
17	Output Limit Exceeded	2020-08-27
16	Wrong Answer	        2020-08-27
15	Wrong Answer	        2020-08-27
14	Compile Error	        2020-08-27
13	Compile Error	        2020-08-27
12	Accepted	            2020-08-27
11	Wrong Answer	        2020-08-27
10	Wrong Answer       	    2020-08-27
9	Accepted	            2020-08-27
8	Wrong Answer	        2020-08-27
7	Wrong Answer	        2020-08-27
6	Wrong Answer	        2020-08-27
5	Wrong Answer	        2020-08-27
4	Wrong Answer	        2020-08-27
3	Wrong Answer	        2020-08-27
2	Wrong Answer	        2020-08-27
1	Wrong Answer	        2020-08-27

方法详解

传送门

PS:只讲方法,不讲题,这两个题差不多

方法一:

#include<iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <algorithm>
#define ll int
#define PI acos(-1)
#define mes(x,y) memset(x,y,sizeof(x))
#define lp pair<ll, ll>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const ll inf = 10000000000000005;
ll n, m, i, j, k = 0, t, w, flag, x, y, z, sum;
string s1, s2, s;
ll tree[2000010], relative[2000010];
ll head(ll x) {
	if (tree[tree[x]] == tree[x])return tree[x];
	head(tree[x]);
	relative[x] = (relative[x] + relative[tree[x]]) & 1;
	return tree[x] = tree[tree[x]];
}
void cmp(ll x, ll y) {
	ll xx = head(x), yy = head(y);
	if (xx != yy) {
		tree[xx] = yy;
		relative[xx] = (relative[x] + relative[y] + 1) & 1;
	}
	xx = head(x), yy = head(y);
	if (xx == yy && relative[x] == relative[y])flag = 1;
}
int main() {
	cin >> k;
	ll tt = 0;
	while (k--) {
		cin >> n >> m;
		for (i = flag = 0, t = w = -1; i <= n; i++)tree[i] = i, relative[i] = 0;
		for (i = 0; i < m; i++) {
			cin >> x >> y;
			if (flag == 0)cmp(x, y);
		}
		cout << "Scenario #" << (tt++) << ":" << endl << (flag ? "Suspicious bugs found!" : "No suspicious bugs found!") << endl << endl;
	}

}

方法二:

#include<iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <functional>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <algorithm>
#define ll int
#define PI acos(-1)
#define mes(x,y) memset(x,y,sizeof(x))
#define lp pair<ll, ll>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const ll inf = 10000000000000005;
ll n, m, i, j, k = 0, t, w, flag, x, y, z, sum;
string s1, s2, s;
ll tree[2000010], relative[2000010];
ll head(ll x) {
	return x == tree[x] ? x : tree[x] = head(tree[x]);
}
int main() {
	cin >> k;
	ll tt = 0;
	while (k--) {
		cin >> n >> m;
		for (i = flag = 0, t = w = -1; i <= n; i++)tree[i] = i, relative[i] = 0;
		for (i = 0; i < m; i++) {
			cin >> x >> y;
			if (head(x) == head(y) || flag == 1) {
				flag = 1; continue;
			}
			ll a = relative[x], b = relative[y];
			if (a) {
				a = head(a); y = head(y);
				if (a != y)tree[a] = y;
			}
			if (b) {
				b = head(b); x = head(x);
				if (b != x)tree[b] = x;
			}
			relative[x] = y; relative[y] = x;
		}
		cout << "Scenario #" << (tt++) << ":" << endl << (flag ? "Suspicious bugs found!" : "No suspicious bugs found!") << endl << endl;
	}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ACM-ICPC(国际大学生程序设计竞赛)是一项全球性的大学生程序设计比赛,每年吸引来自世界各地的顶尖大学代表队参与。ACM-ICPC竞赛的核心内容是团队编程和问题解决能力。 首先,ACM-ICPC竞赛对参赛选手的编程能力要求很高。参赛队伍需要在规定的时间内解决一系列的算法问题,这些问题常常包含复杂的数据结构和算法,要求选手在有限的时间内设计和实现高效的程序。 其次,ACM-ICPC竞赛强调团队协作。每个队伍由三名选手组成,他们需要分工合作,保持良好的沟通与协调,共同解决问题。团队成员需要相互理解、相互信任,快速地协商和决策,同时要保持高效的任务分配和时间管理。 此外,ACM-ICPC竞赛也需要选手具备良好的问题解决能力。这些问题往往是实际应用或理论推导相关的,选手需要从数学、计算机科学和算法等多个角度出发,找到最佳解决方案。在面对问题时,选手需要对问题进行分析、抽象和建模,运用各种算法和数据结构进行解决。 对于参赛选手来说,ACM-ICPC提供了一个学习与交流的平台。在比赛中,选手可以接触到不同国家和地区的优秀程序设计人才,学习他们的思维方式和编程技巧。同时,ACM-ICPC还举办了一系列的培训和研讨会,让选手有机会深入了解计算机科学和算法领域最新的研究成果。 总之,ACM-ICPC国际大学生程序设计竞赛是一个挑战性与学习性兼具的比赛。它要求选手具备扎实的编程技能、团队合作能力和问题解决能力。参与此竞赛不仅可以锻炼自己的编程能力,还能与全球的顶尖程序设计人才进行交流,拓宽自己的视野和思维方式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GUESSERR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值