连接:传送门
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.
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).
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.
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
3 fegla fouad nicole 1 fegla
题意:
将有时间冲突的志愿者找出来,按字典序输出
思路:
将所有志愿者存放到map中,将多次出现在比赛的志愿者的开始和结束时间存放到vector容器中,再用set容器将有冲突的志愿者存放起来,最后输出set容器中的元素,c++的STL真是强大
map:连接传送门
set:连接传送门
vector:连接传送门
代码如下:
#include<iostream> #include<vector> #include<map> #include<stack> #include<queue> #include<string.h> #include<cmath> #include<stdio.h> #include<algorithm> #include<set> using namespace std; map<string,int>mymap; set<string>vl; vector<pair<int,int> >v[11000]; string s[11000]; 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,n,st,et,vn;string str;scanf("%d",&t);set<string>::iterator it;while(t--){vl.clear();scanf("%d",&n);mymap.clear();int ans=0;for(int i=0;i<n;i++){cin>>str>>st>>et>>vn;for(int j=0;j<vn;j++){cin>>str;if(mymap[str])//之前存在,将时间记录下来v[mymap[str]].push_back(make_pair(st,et));else{mymap[str]=++ans;//标号s[ans]=str;v[ans].clear();v[ans].push_back(make_pair(st,et));}}}for(int i=1;i<=ans;i++){if(v[i].size()==1)//没有重复的continue;sort(v[i].begin(),v[i].end(),cmp);for(int j=0;j<v[i].size()-1;j++){if(v[i][j].second>=v[i][j+1].first)//判断时间是否冲突vl.insert(s[i]);}}cout<<vl.size()<<endl;for(it=vl.begin();it!=vl.end();++it)cout<<*it<<endl;}return 0; }