cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)

题目:

Description

standard input/output

As most of you know, the Arab Academy for Science and Technology and Maritime Transport in Alexandria, Egypt, hosts the ACPC Headquarters in the Regional Informatics Center (RIC), and it has been supporting our region with all kinds of resources it can provide, whether it was hosting nationals, regionals, or providing support for national contests around the Arab Region by sending its employees and students to participate in preparing contest systems, coaching, problem setting, and whatever these nationals ask for. However, ACPC's volunteers' schedules can get very busy, therefore, some conflicts might occur between the nationals they are assigned to help with. As to resolve these conflicts, Noura suggested that the SCPC2015 students can come up with a program that detects the conflicts in the contests' schedule, and that is, detect for each volunteer whether they have been assigned to multiple contests running at the same time.

Given the requirements for each contest (contest name, start date, end date, number of required volunteers, volunteers' names), print a list of volunteers' names that have conflicts in their schedules, sorted in alphabetical order.

Input

The first line of input contains an integer T (1 ≤ T ≤ 64), the number of test cases.

The first line of each test case contains an integer N (1 ≤ N ≤ 100), the number of contests.

Each of the following N lines contains one contest's data: Contest name C, start date S, end date E, number of required volunteers V, followed by V distinct volunteers' names.

Names consist of lowercase Latin letters, and their length doesn't exceed 10 letters.

You may assume that (1 ≤ S ≤ E ≤ 365) and (1 ≤ V ≤ 100).

Output

For each test case, print the number of volunteers that have conflicts in their schedules, followed by the names of the volunteers in alphabetical order, each on a single line.

Sample Input

Input
2
2
lcpc 3 7 4 fegla compo fouad nicole
scpc 5 11 3 fegla fouad nicole
2
jcpc 8 10 2 fegla hossam
scpc 10 15 3 fegla fouad nicole
Output
3
fegla
fouad
nicole
1
fegla

题意:给出n个比赛开始时间,结束时间,志愿者人数及名单,输出参加的比赛时间有重合的志愿者名字,按字母序输出

分析:第一交的时候TLE了,第一次我是先判断哪些比赛时间重合了,然后再对时间重合的比赛需要的志愿者进行判断是否重合了。再次看题后发现,其实没必要先判断比赛时间是否重合,因为题目只要求有比赛时间重合的志愿者就输出,可以直接判断每个志愿者是否有比赛时间重合即可。

代码:

 #include<iostream>
#include<stdio.h>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
using namespace std;
map<string,int>mp;
vector<pair<int,int> >v[];
vector<string>ans;
string s[];
int cmp1(string s,string t){return s<t;}
int cmp(pair<int,int>a,pair<int,int>b)
{
if(a.first==b.first)
return a.second<b.second;
return a.first<b.first;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
mp.clear();
ans.clear();
int n,st,en,vol;
int cnt=;
string na;
scanf("%d",&n);
for(int i=;i<n;i++)
{
cin>>na>>st>>en>>vol;
for(int j=;j<vol;j++)
{
cin>>na;
if(mp[na])
v[mp[na]].push_back(make_pair(st,en));
else
{
mp[na]=++cnt;
s[cnt]=na;
v[cnt].clear();
v[cnt].push_back(make_pair(st,en));
}
}
}
//cout<<cnt<<endl;
for(int i=;i<=cnt;i++)
{
//cout<<v[i].size()<<endl;
if(v[i].size()==)
continue;
sort(v[i].begin(),v[i].end(),cmp);
for(int j=;j<v[i].size()-;j++)
{
if(v[i][j].second>=v[i][j+].first)
{
ans.push_back(s[i]);
break;
}
}
}
sort(ans.begin(),ans.end(),cmp1);
printf("%d\n",ans.size());
for(int i=;i<ans.size();i++)
cout<<ans[i]<<endl;
}
return ;
}
上一篇:memcache原理、简单使用、分布式实现方案


下一篇:Tcl与Design Compiler (九)——综合后的形式验证