思路:标记课程表上的课程,询问时遍历课程表,再以字典序输出名字。
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<stack>
const int MAXX= ;
const int mod=1e9+;
using namespace std;
typedef long long ll;
int T;
int n;
int q;
int k;
struct info
{
bool data[][];
char name[];
} per[]; struct pp
{
char ans[];
} w[]; bool cmp(pp a,pp b)
{
return strcmp(a.ans,b.ans)<;
} int main()
{
freopen("in.txt","r",stdin);
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
memset(per,,sizeof(per));
for(int i=; i<=n; i++)
{
int d,b,e;
scanf("%s%d",per[i].name,&k);
for(int j=; j<=k; j++)
{
scanf("%d%d%d",&d,&b,&e);
while(b<=e)
{
per[i].data[d][b]=;
b++;
}
//memset(per[i].data[d]+b,1,(e-b+1)*sizeof(per[i].data[0][0]));
}
}
scanf("%d",&q);
while(q--)
{
int d,b,e;
scanf("%d%d%d",&d,&b,&e);
//char newname[200][22];
int countt=;
for(int i=; i<=n; i++)
{
bool flag=;
for(int j=b; j<=e; j++)
{
if(per[i].data[d][j])
{
flag=;
break;
}
}
if(!flag)
{
strcpy(w[countt].ans,per[i].name);
countt++;
}
}
if(countt==)
{
cout<<"None"<<endl;
continue;
}
sort(w,w+countt,cmp);
for(int i=; i<countt; i++)
{
if(i)
printf(" ");
printf("%s",w[i].ans);
}
//printf("%s\n",newname[countt-1]);
printf("\n");
}
}
return ;
}