10317 Fans of Footbal Teams
10317 Fans of Footbal Teams
时间限制:1000MS 内存限制:65535K
提交次数:0 通过次数:0
题型: 编程题 语言: G++;GCC
Description
Two famous football teams, named AC Milan(AC米兰) and Inter Milan(国际米兰) will have a match in GuangZhou City, which is
exciting. So a lot of fans get together to watch the wonderful match. This trouble the local polices. In order to avoid a
chaos caused by fans of the two teams, the police office in GuangZhou City decides to arrange the seats of the gymnasium(体育馆)
during the match. All fans of AC Milan seat Noth, while all fans of Inter Milan seat South . However, the police first needs
to identify which team a fan support. The present question is, given two fans; do they support a same team? You must give
your judgment based on incomplete information. Assume N (N <= 10^5) fans are currently in GuangZhou City, numbered from 1 to N. You will be given M (M <= 10^5) messages
in sequence, which are in the following two kinds: 1. D [a] [b]
where [a] and [b] are the numbers of two fans, and they support different teams. 2. A [a] [b]
where [a] and [b] are the numbers of two fans. This requires you to decide whether a and b support a same team.
输入格式
The first line of the input contains a single integer T (1 <= T <= 20), the number of test cases. Then T cases follow.
Each test case begins with a line with two integers N and M, followed by M lines each containing one message as described above.
输出格式
For each message "A [a] [b]" in each case, your program should give the judgment based on the information got before.
The answers might be one of "Support the same team.", "Support different teams." and "Not sure yet."
输入样例
1
5 5
A 1 2
D 1 2
A 1 2
D 2 4
A 1 4
输出样例
Not sure yet.
Support different teams.
Support the same team.
作者
admin
题意很好理解,,,就是给出信息语句告诉你哪两个人是支持不同队的,,,然后还有询问语句询问两个人是否是支持同一队伍;我解这题的解法是略有点奇葩的,,,算是套用了poj 1182(并查集经典题目,没做的话可以了解下)这道题的解法。。。既然是只提供信息说某两个人是支持不同的队伍,那么用 f[i]=i 表示"第i个人支持的队伍是跟某个人支持的队伍相同的"这一事件;而 f[i+n]=i+n 表示 "事件f[i]=i 的对立事件";注意!这里的数组f[i]=i的意思是"编号i的人支持某支队伍"事件(不用理会他实际支持的是什么队),而不是指编号为i的人!如果数据给了D 2 5的话,那就把f[2]和f[5+n]合并,f[2+n]和f[5]合并;因为如果编号2和5的人支持不同的队伍,那么f[2]和 "f[5]的对立事件"-f[5+n]必定是同时存在的,而f[2]的对立事件f[2+n]是和f[5]同时存在的。
上面的话理解可能有点绕,,,可以直接看代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <utility>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std; int t,n,m,temp;
int f[];//记录父亲结点
int father(int u) //寻找父亲
{
if(f[u]==u)
return u;
return f[u]=father(f[u]);
}
void unite(int x,int y)//合并x和y两个集合
{
int tx=father(x),ty=father(y);
if(tx!=ty)
f[ty]=tx;
}
bool same(int x,int y)//判断x和y是否属于同一集合
{
return father(x)==father(y);
}
int main()
{
//freopen("input.txt","r",stdin);
scanf("%d",&t);
while(t--)
{
char str[];
int a,b;
scanf("%d%d",&n,&m);
temp=*n;
for(int i=;i<=temp;i++)
f[i]=i;
while(m--)
{
scanf("%s%d%d",str,&a,&b);
if(str[]=='D')
{ //将a和b+n合并,b和a+n合并
unite(a,b+n);
unite(a+n,b);
}
else
{
if(same(a,b+n))
printf("Support different teams.\n");
else if(same(a,b))
printf("Support the same team.\n");
else
printf("Not sure yet.\n"); }
}
}
return ;
}
其实这题也可以不用这么傻逼的做法的,,,同宿舍的大神告诉我其实用结构体存数据,然后里面再加个数据域用来存放第i个人的对立队伍的集合编号就可以了
10317 Fans of Footbal Teams的更多相关文章
- SCAU 07校赛 10317 Fans of Footbal Teams
10317 Fans of Footbal Teams 时间限制:1000MS 内存限制:65535K 题型: 编程题 语言: 无限制 Description Two famous footba ...
- 10317 Fans of Footbal Teams(并查集)
10317 Fans of Footbal Teams 时间限制:1000MS 内存限制:65535K提交次数:0 通过次数:0 题型: 编程题 语言: G++;GCC Description ...
- Guardian of Decency(二分图)
Guardian of Decency Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- Poj(2771),最大独立集
题目链接:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K To ...
- POJ 2771 二分图(最大独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5244 Accepted: 21 ...
- POJ2771_Guardian of Decency(二分图/最大独立集=N-最大匹配)
解决报告 http://blog.csdn.net/juncoder/article/details/38159017 题目传送门 题意: 看到题目我就笑了.., 老师觉得这种两个学生不是一对: 身高 ...
- TZOJ 二分图练习
二分图主要是 1.如何建图,谁匹配谁,怎么匹配 2.判断求的是什么:最大匹配=最小点覆盖,最大独立子集=最小路径覆盖=最小边覆盖=图中顶点数-最大匹配 A.2733:棋盘游戏 描述 小希和Gardon ...
- POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)
题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...
- POJ 2771 Guardian of Decency 【最大独立集】
传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Tot ...
随机推荐
- 微信js sdk上传多张图片
微信js sdk上传多张图片,微信上传多张图片 该案例已tp3.2商城为例 直接上代码: php代码: public function ind(){ $appid="111111111111 ...
- JS通过ajax + 多列布局 + 自动加载来实现瀑布流效果
Ajax 说明:本文效果是无限加载的,意思就是你一直滚动就会一直加载图片出现,通过鼠标滚动距离来判断的,所以不是说的那种加载一次就停了的那种,那种demo下次我会再做一次 css部分用的是html5+ ...
- B - Is your horseshoe on the other hoof?
Problem description Valera the Horse is going to the party with friends. He has been following the f ...
- Django html页面 'ascii' codec can't encode characters in position 8-10: ordinal not
用Django开发的页面,之前用的是python3.X,后来又换成python2.X后各种报错,编码问题,于是在所有python文件开头加了编码:#coding=utf-8 但是后来发现,有些文件加了 ...
- 项目平台统一(前后端IDE、代码风格)
项目平台统一(前后端IDE.代码风格) 记录人:娄雨禛 前端:Webstorm(HTML+CSS+JavaScript) 后端:IntelliJ IDEA(Java) 代码风格:Java风格代码 代码 ...
- 【SQL】ROWNUM和ROWID
一.ROWNUM ROWNUM伪列是Oracle先查到结果集之后再加上去的一个伪列,这个伪列对符合条件的结果添加一个从1开始的序列号,并且序列号是从1开始增序排列的. SQL> select r ...
- 图像局部显著性—点特征(FREAK)
参考文章:Freak特征提取算法 圆形区域分割 一.Brisk特征的计算过程(参考对比): 1.建立尺度空间:产生8层Octive层. 2.特征点检测:对这8张图进行FAST9-16角点检测,得到具 ...
- java这个404你能解决吗?
前言 本文首发于公众号[我的小碗汤]本公众号免费提供csdn下载服务,海量IT学习资源,如果你准备入IT坑,励志成为优秀的程序猿,那么这些资源很适合你,包括但不限于java.go.python.spr ...
- <转>python 发送邮件实例
文件形式的邮件 #!/usr/bin/env python3 #coding: utf-8 import smtplib from email.mime.text import MIMEText fr ...
- Git更新代码
此次更新,创建新的文件与文件夹,并且删除了原有文件 通过“git status” 命令查看当前变更.通过变更信息可以看出,删除了test_case.py文件.这个删除只是在项目目录下进行删除,Git对 ...