码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-09-14 23:18:16      阅读:388      评论:0      收藏:0      [点我收藏+]

标签:

题目:

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

代码:

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<vector>
 4 #include<map>
 5 #include<algorithm>
 6 #include<set>
 7 #include<string>
 8 #include<string.h>
 9 using namespace std;
10 map<string,int>mp;
11 vector<pair<int,int> >v[11000];
12 vector<string>ans;
13 string s[11000];
14 int cmp1(string s,string t){return s<t;}
15 int cmp(pair<int,int>a,pair<int,int>b)
16 {
17     if(a.first==b.first)
18         return a.second<b.second;
19     return a.first<b.first;
20 }
21 int main()
22 {
23     int t;
24     scanf("%d",&t);
25     while(t--)
26     {
27         mp.clear();
28         ans.clear();
29         int n,st,en,vol;
30         int cnt=0;
31         string na;
32         scanf("%d",&n);
33         for(int i=0;i<n;i++)
34         {
35             cin>>na>>st>>en>>vol;
36             for(int j=0;j<vol;j++)
37             {
38                  cin>>na;
39                  if(mp[na])
40                     v[mp[na]].push_back(make_pair(st,en));
41                  else
42                  {
43                      mp[na]=++cnt;
44                      s[cnt]=na;
45                      v[cnt].clear();
46                      v[cnt].push_back(make_pair(st,en));
47                  }
48             }
49         }
50         //cout<<cnt<<endl;
51         for(int i=1;i<=cnt;i++)
52         {
53             //cout<<v[i].size()<<endl;
54             if(v[i].size()==1)
55                 continue;
56             sort(v[i].begin(),v[i].end(),cmp);
57             for(int j=0;j<v[i].size()-1;j++)
58             {
59                 if(v[i][j].second>=v[i][j+1].first)
60                 {
61                     ans.push_back(s[i]);
62                     break;
63                 }
64             }
65         }
66         sort(ans.begin(),ans.end(),cmp1);
67         printf("%d\n",ans.size());
68         for(int i=0;i<ans.size();i++)
69             cout<<ans[i]<<endl;
70     }
71     return 0;
72 }

 

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

标签:

原文地址:http://www.cnblogs.com/tristatl/p/5873642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!