10317 Fans of Footbal Teams

时间限制:1000MS  内存限制:65535K

题型: 编程题   语言: 无限制

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

解题思路

【题意】AC米兰和国际米兰要在广州比赛从而吸引众多的球迷前来观看,为了保证治安问题保安要为球迷分配观看的位置,现在需要知道哪些球迷支持相同的球队,哪些球迷支持不同的球迷,现在根据给的数据n(球迷的数量,编号从1到n),m(条信息,说明这两个球迷支持相反的球队或需要你输出判断这两个球迷支持球队的信息)

【随笔】开始认为只有两种情况,要么支持相同的球队,要么支持相反的球队,打算用一个数组就解决问题,后来发现这样下去有问题,比如出现两组支持不同球队的四个人,然后接下来的某条信息将其中的两个人联系起来,那么从中还可以得到四个人的信息,手写出数据来试着分析很容易发现其中的规律

D 1 2; D 2 4; D 3 5; D 7 8; D 5 2; D 1 7; D 6 9; D 6 10;

【解题】~并查集~给你的D中的数据主要分三种情况,两个球迷之前均没表明立场的;其一表明立场的;两者均有表明立场的;用一个数组构造并查集,用另一数组存储各自的死对头,死对头每次我都及时更新,其实后来想想是没必要的,因为敌人的敌人就是朋友,在构成的并查集里最终还是能找到源点表明不同的立场。存储死对头主要是想判断是否是”无法判断“这种情况。而存储死对头的还有一个作用是找到死对头的源点,将此时新增的死对头加入此行列。并查集查找源点的时候即使压缩路径,所以尽管每次都去查找,但是消耗的时间还不是很多。

【PS】这题恶心了好长的一段时间,主要是思路还不是很清晰,现在回想很多想法和考虑到的东西以及实现的方法还是没必要的,这里已经浪费了大半的时间

 #include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#define MAXN 100010 using namespace std; int middle[MAXN], digit[MAXN];
char same[] = "Support the same team.";
char dif[] = "Support different teams.";
char mix[] = "Not sure yet."; int find_father(int fac)
{//查找源头并及时压缩路径
return middle[fac] = fac == middle[fac] ? fac : find_father(middle[fac]);
} /*
void Print(int n)
{
static int cnt = 0;
for(int i=1; i<=n; i++)
{
printf("middle[%d] = %d, D[%d] = %d\n", i, middle[i], i, digit[i]);
}
printf("-------------------%d----------------------\n", ++cnt);
}
*/ int main()
{
#ifndef ONLINE_JUDGE
freopen("F:\\test\\input.txt", "r", stdin);
#endif // ONLINE_JUDGE int T;
int n, m, first, second, sum;
int father, foster, fir_father, sec_father, fir_foster, sec_foster;
char kind;
bool falg = false;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
for(int i=; i<=n; ++i)
{
middle[i] = i;
digit[i] = ;
}
for(int i=; i<m; ++i)
{
getchar();
scanf("%c", &kind);
scanf("%d%d", &first, &second);
if(kind == 'A')
{
fir_father = find_father(first);
sec_father = find_father(second);
if(fir_father == sec_father)
printf("%s\n", same);
else
{
fir_foster = find_father(digit[fir_father]);
if(fir_foster == sec_father)
printf("%s\n", dif);
else
printf("%s\n", mix);
} }
else if(kind == 'D')
{
if(!digit[first] && !digit[second])
{//互相存储死对头的编号
digit[first] = second;
digit[second] = first;
}
else if(!digit[first] && digit[second])
{
father = find_father(second);
foster = find_father(digit[father]);
middle[foster] = first;
digit[first] = father;
}
else if(digit[first] && !digit[second])
{
father = find_father(first);
foster = find_father(digit[father]);
middle[foster] = second;
digit[second] = father;
}
else
{
fir_father = find_father(first);
sec_father = find_father(second);
fir_foster = find_father(digit[fir_father]);
sec_foster = find_father(digit[sec_father]);
middle[fir_foster] = sec_father;
middle[sec_foster] = fir_father;
}
}
}
} return ;
}

SCAU 07校赛 10317 Fans of Footbal Teams的更多相关文章

  1. 10317 Fans of Footbal Teams(并查集)

    10317 Fans of Footbal Teams 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description ...

  2. 10317 Fans of Footbal Teams

    10317 Fans of Footbal Teams 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description ...

  3. SCAU 13校赛 17115 ooxx numbers

    17115 ooxx numbers 时间限制:1000MS  内存限制:65535K 题型: 编程题   语言: 无限制 Description a number A called oo numbe ...

  4. 2015 GDUT校赛

    周末打了个GDUT的校赛,也是作为SCAU的一场个人排位. 比赛中竟然卡了个特判,1个半钟就切了5条了,然后一直卡. 还有其他两条可以做的题也没法做了,性格太执着对ACM来说也是错呀. 讲回正题 . ...

  5. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  6. SCNU省选校赛第二场B题题解

    今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...

  7. 2014上半年acm总结(1)(入门+校赛)

    大一下学期才开始了acm,不得不说有一点迟,但是acm确实使我的生活充实了很多,,不至于像以前一样经常没事干=  = 上学期的颓废使我的c语言学的渣的一笔..靠考前突击才基本掌握了语法 寒假突然醒悟, ...

  8. 2017CUIT校赛-线上赛

    2017Pwnhub杯-CUIT校赛 这是CUIT第十三届校赛啦,也是我参加的第一次校赛. 在被虐到崩溃的过程中也学到了一些东西. 这次比赛是从5.27早上十点打到5.28晚上十点,共36小时,中间睡 ...

  9. HZNU第十二届校赛赛后补题

    愉快的校赛翻皮水! 题解 A 温暖的签到,注意用gets #include <map> #include <set> #include <ctime> #inclu ...

随机推荐

  1. [Codeforces673B]Problems for Round(思路,规律)

    题目链接:http://codeforces.com/contest/673/problem/B 现在有n个题和m个相似的关系,现在要把他们分到2组去. 要求: 1组的所有题比2组难 每个组都得至少有 ...

  2. Android 中Activity生命周期分析:Android中横竖屏切换时的生命周期过程

    最近在面试Android,今天出了一个这样的题目,即如题: 我当时以为生命周期是这样的: onCreate --> onStart -- ---> onResume ---> onP ...

  3. CXF客户端异常

    基于CXF2.3.0 Caused by: java.lang.InstantiationException: org.apache.cxf.wstx_msv_validation.WoodstoxV ...

  4. ASP.NET MVC 学习2、从Controller传递数据到View

      参考:http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-view 一,Control ...

  5. MVC的项目使用html编辑器UEditorMINI

    一个MVC的项目中有个发布新闻的页面需要用到一个html的编辑器,网上看到UEditor评价貌似还不错, 因为我用到的功能比较简单,就下载了MINI版本的, 使用的过程在这里总结一下. 关于UEdit ...

  6. UVa 11995 I Can Guess the Data Structure!

    做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...

  7. UVA 10765 Doves and bombs(双连通分量)

    题意:在一个无向连通图上,求任意删除一个点,余下连通块的个数. 对于一个非割顶的点,删除之后,原图仍连通,即余下连通块个数为1:对于割顶,余下连通块个数>=2. 由于是用dfs查找双连通分量,树 ...

  8. HDU 1272 小希的迷宫 (水题)

    题意: 其实就是让你判断一个图是否为树,要求不能有孤立的点(没有这中情况),且只能有1个连通图,且边数+1=点数,且每个点都有边(不可能只有1个点出现). 思路: 有可能出现连续的4个0,也就是有测试 ...

  9. ftp在shell脚本中的使用方法

    1. ftp自动登录批量下载文件. #####从ftp服务器上的/home/data 到 本地的/home/databackup#####!/bin/bashftp -n<<!open 1 ...

  10. 一个响应式框架——agera

    Google在上周开源了一个响应式框架——agera,相信它会慢慢地被广大程序员所熟知.我个人对这样的技术是很感兴趣的,在这之前也研究过RxJava,所以在得知Google开源了这样的框架之后第一时间 ...