题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1707
思路:memset妙用,把当天的上课时间标记为true..然后查询的时候进行遍历就行了。
View Code
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cstdlib> 6 using namespace std; 7 #define MAXN 222 8 struct Person{ 9 bool time[11][14]; 10 char name[22]; 11 }Per[MAXN]; 12 int n; 13 14 int cmp(const void *a,const void *b){ 15 return (strcmp((char *)a,(char *)b)); 16 } 17 18 int main(){ 19 int _case; 20 scanf("%d",&_case); 21 while(_case--){ 22 memset(Per,false,sizeof(Per)); 23 int n,k,d,s,e; 24 scanf("%d",&n); 25 for(int i=1;i<=n;i++){ 26 scanf("%s%d",Per[i].name,&k); 27 while(k--){ 28 scanf("%d%d%d",&d,&s,&e); 29 memset(Per[i].time[d]+s,true,(e-s+1)*sizeof(Per[i].time[0][0])); 30 } 31 } 32 scanf("%d",&k); 33 while(k--){ 34 scanf("%d%d%d",&d,&s,&e); 35 char str[MAXN][22]; 36 int count=0; 37 for(int i=1;i<=n;i++){ 38 bool flag=true; 39 for(int j=s;j<=e;j++){ 40 if(Per[i].time[d][j]){flag=false;break;} 41 } 42 if(!flag){strcpy(str[count++],Per[i].name);} 43 } 44 if(count==0){puts("None");continue;} 45 qsort(str,count,sizeof(str[0]),cmp); 46 for(int i=0;i<count-1;i++){ 47 printf("%s ",str[i]); 48 } 49 printf("%s\n",str[count-1]); 50 } 51 } 52 return 0; 53 } 54 55 56 57