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个人的对立队伍的集合编号就可以了

最新文章

  1. wiseinstall 制做安装包小记
  2. java implement
  3. C# - 系统类 - String类
  4. asp.net 字符帮助类 类型转换类
  5. C#读取USB的一些相关信息
  6. JAVA 公众微信的开放源码项目管理合作伙伴招募的版本号
  7. python3中的一些小改动
  8. 为什么vue里面data里面的对象,无法用delete删除属性
  9. composer的安装方法 以及 ThinkPHP5安装
  10. php与java通用AES加密解密算法
  11. python 多环境共存 基础
  12. java中函数传值和传地址的问题
  13. P2763 试题库问题(dinic)
  14. linux定时删除文件脚本
  15. :组合模式:Component
  16. 根据城市表生成json数据
  17. sea.js常用接口
  18. Jersey 2.x 服务器端应用支持的容器
  19. 分类Category的概念和使用流程
  20. 裸函数naked解析

热门文章

  1. Github标星4W+,热榜第一,如何用Python实现所有算法
  2. vs2008 启动IE浏览器 出现DW20.exe占用大量cpu 服务器iis 异常调试
  3. struts2结果处理、获取参数(二)
  4. oracle排序union和union all区别
  5. QtUI设计:设置控件透明
  6. 【Hexo】本地local4000打不开解决方法
  7. react基础篇一
  8. node phantomjs linux 安装问题
  9. H3C交换机配置学习随笔
  10. Mark Zuckberg: A letter to our daughter