Gym 100952 F. Contestants Ranking
1 second
24 megabytes
standard input
standard output
Ahmad is one of the best students in HIAST, and also a very good problems Solver. In the time you will spend reading this problem statement Ahmad would have solved a problem. Maybe, even two... Ahmad participated so many times in programming contest (ACM-HCPC) with several teams. many of the former and present contestants at HIAST have known Ahmad for quite a few years. Some of them are proud to say that they either played in the same team with him or played in the same team with one of his teammates... Let us define ranking number as follows. Ahmad's ranking is 0, for people who played in the same team with him, the ranking is 1. For people who never played with Ahmad but played in the same team with one or more of his teammates, the ranking is 2, and so on. Your task is to automate the process of calculating the ranking numbers for each contestant at HIAST.
The first line of input file contains the number of test cases (0<T<10). Each test case will begin with one line containing the number of teams (1<N ≤ 100). In each of the following N lines you are given the names of the three members of the corresponding team. Each name is a nonempty string contains only English letters starts with capital letter, and its length is at most 20 symbols. Same student can be found in more than one team, but each student should have only one rank. Ahmad will be found in one team at least. The first letter of a name is capital and the other letters are lowercase and each name will consist of only one word.
For each test case output a line with the number of contestants, then for each contestant output a line with his name and his ranking. If the ranking is undefined, output “undefined” instead of it. The contestants must be ordered by rank from 0 to undefined and then lexicographical by name.
2
1
Ahmad Mousaab Khalid
7
Ahmad Mousaab Khalid
Ali Mousaab Nizar
Ali Bassel Nizar
Kassem Ahmad Mousaab
Saeed Kassem Fadel
Salwa Saeed Samer
Mona Abdo Qussi
3
Ahmad 0
Khalid 1
Mousaab 1
14
Ahmad 0
Kassem 1
Khalid 1
Mousaab 1
Ali 2
Fadel 2
Nizar 2
Saeed 2
Bassel 3
Salwa 3
Samer 3
Abdo undefined
Mona undefined
Qussi undefined
每次先确定一个等级在查找下个等级,没有等级的视为undefined
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
string s[][],name="Ahmad";
map<string,int>m;
set<string>ans[],pos;
int t,n;
void check(int x,int y,int z)
{
if(ans[x].count(s[y][z]))
{
for(int i=;i<=;i++)
{
if(m[s[y][(z+i)%]]==)
{
ans[x+].insert(s[y][(z+i)%]);
m[s[y][(z+i)%]]=;
}
}
}
}
void check_undefined(int n)
{
for(int i=;i<n;i++)
{
for(int j=;j<;j++)
{
if(m[s[i][j]]==) pos.insert(s[i][j]),m[s[i][j]]=;
}
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<n;i++)
{
for(int j=;j<;j++)
{
cin>>s[i][j];
}
}
m[name]=;
ans[].insert(name);
for(int i=;i<n;i++)
{
for(int j=;j<n;j++)
{
for(int k=;k<;k++)
{
check(i,j,k);
}
}
}
check_undefined(n);
printf("%d\n",m.size());
for(int i=;i<=n;i++)
{
if(ans[i].size()==) break;
for(set<string>::iterator it=ans[i].begin();it!=ans[i].end();it++)
cout<<*it<<' '<<i<<endl;
}
for(set<string>::iterator it=pos.begin();it!=pos.end();it++)
cout<<*it<<" undefined"<<endl;
for(int i=;i<;i++)
ans[i].clear();
pos.clear();
m.clear();
}
return ;
}
Gym 100952 F. Contestants Ranking的更多相关文章
- Gym 100952F&&2015 HIAST Collegiate Programming Contest F. Contestants Ranking【BFS+STL乱搞(map+vector)+优先队列】
F. Contestants Ranking time limit per test:1 second memory limit per test:24 megabytes input:standar ...
- codeforces gym 100952 A B C D E F G H I J
gym 100952 A #include <iostream> #include<cstdio> #include<cmath> #include<cstr ...
- Gym 100952 H. Special Palindrome
http://codeforces.com/gym/100952/problem/H H. Special Palindrome time limit per test 1 second memory ...
- Gym 100952 D. Time to go back(杨辉三角形)
D - Time to go back Gym - 100952D http://codeforces.com/gym/100952/problem/D D. Time to go back time ...
- Gym 100952 G. The jar of divisors
http://codeforces.com/gym/100952/problem/G G. The jar of divisors time limit per test 2 seconds memo ...
- Gym 100952 D. Time to go back
http://codeforces.com/gym/100952/problem/D D. Time to go back time limit per test 1 second memory li ...
- Gym 100952 C. Palindrome Again !!
http://codeforces.com/gym/100952/problem/C C. Palindrome Again !! time limit per test 1 second memor ...
- Gym 100637F F. The Pool for Lucky Ones
F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- codeforces Gym 100187F F - Doomsday 区间覆盖贪心
F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...
随机推荐
- 隐私:随机选择 MAC 地址
隐私:随机选择 MAC 地址 从 Android 8.0 开始,Android 设备在未连接到网络的情况下探测新网络时会使用随机 MAC 地址. 在 Android 9 中,您可以启用开发者选项(默认 ...
- CentOS6.9下sftp配置和scp用法
基于 ssh 的 sftp 服务相比 ftp 有更好的安全性(非明文帐号密码传输)和方便的权限管理(限制用户的活动目录). 1.如果只想让某些用户只能使用 sftp 操作文件, 而不能通过ssh进行服 ...
- python 异步IO
参考链接:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143208573 ...
- Zookeeper入门-Java版本HelloWorld例子
上一篇介绍了,Zookeeper的基本概念,怎么启动,怎么解决可能遇到的几个问题.本篇,根据网上代码,整理了一个例子,Zookeeper的HelloWorld. 下面这个代码,还是比较简单的,核心类就 ...
- Android之Handler源代码深入解析
闲着没事.就来看看源代码,看看源代码的各种原理,会用仅仅是简单的,知道为什么才是最牛逼的. Handler源代码分析那,从使用的步骤来边用边分析: 1.创建一个Handler对象:new Handle ...
- bzoj1066【SCOI2007】蜥蜴
1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 2512 Solved: 1238 [Submit][Statu ...
- Linux打包免安装的Qt程序(编写导出依赖包的脚本copylib.sh,程序启动脚本MyApp.sh)
本文介绍如何打包Qt程序,使其在没有安装Qt的系统可以运行. 默认前提:另外一个系统和本系统是同一个系统版本. 1,编写导出依赖包的脚本copylib.sh #!/bin/bash LibDir=$P ...
- HTML5新增的一些特性
HTML现在已经不是SGML的子集,主要是关于图像,位置,储存,多任务等功能的增加. .绘画canvas: .用于媒介回放的video: Ogg是带有Theora视频编码和Vorbis音频编码的文件: ...
- 新手教程:电信+广电(或其他运营商)双WAN设置
由于国内不同运营商之间互联互通存在问题,假如用联通的线路去访问电信的站点那么会比较卡,反之亦然:所以如果两个WAN的线路不是同一个运营商,一般都是建议用户双WAN模式选为“智能路由”.经过本人测试发现 ...
- MYSQL常用命令列表
MYSQL常用命令列表 1.系统管理 mysql -h主机地址 -u用户名 -p 连接MYSQL(在mysql/bin) exit 退出MYSQL命令 mysqladmin -u用户名 -p旧密码 p ...