ACPC Headquarters : AASTMT (Stairway to Heaven)


          连接:传送门

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.

Example
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


题意:

将有时间冲突的志愿者找出来,按字典序输出

思路:

将所有志愿者存放到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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值