HDU 1707 Spring-outing Decision

来源:互联网 发布:上海行知教育 编辑:程序博客网 时间:2024/06/07 12:15
Problem Description
Now is spring ! The sunshine is warm , the flowers is coming out . How lovely it is! So my classmates and I want to go out for a spring-outing.

But we all select courses ourselves. We don't have classes at the same time.Now our monitor has a big trouble in arranging the time of the spring-outing.

Can you help him?

I will give you our courses information and the time of the spring-outing.You just need to tell me that who can't go with us. 
 

Input
The first line contains an integer CA which indicates the number of test cases.
Then CA cases follow.
Each case contains two parts,the students' courses information and the query.

In the first part ,first there is an integer N(N<200) which means the number of the student,and then comes the N students’ courses information.
A student's courses information is in this format:

line1: name K
line2: day1 b1 e1
.....
lineK+1: dayK bK eK

The first line of a student's courses infomation contains his name(less than 20 characters and in lowercase) and the number(K,K<1000) of his courses . Then next K lines describe his courses. Each Line contain three integers indicate the day of a week( 1 <= day <= 7 means Monday to Sunday ), the begin time and the end time of the course.
To make the problem easier,the begin time and the end time will be in the range from 1 to 11 .(Because in HDU,there is 11 classes one day).

In the query part , first there is an integer Q which means the query number,and then Q lines follow.
A query contains three integers which means the day ,the begin time and the end time of the spring-outing.And the time is described as the courses.
Notice,everyone may have more than one course at the same time for some special reasons.
 

Output
For each query , just print the names of the students who can't go out for a spring-outing in a line in lexicographic order.
Please separate two names with a blank.
If all of the students have time to go , just print "None" in a line.
 

Sample Input
13linle 31 1 22 3 43 8 10laili 14 1 4xhd 21 2 44 5 631 2 24 4 55 1 2
 

Sample Output
linle xhdlaili xhdNone
题目大意:
一群孩子要去春游,给出他们的课程时间安排,求出某一特定春游计划中,那些人不能来,并以字典序输出,都可以去,输出None
大致思路就是去匹配每个时间段有没有冲突,由于数据不大,大可以把学生所有时间都列出来,纪录下来,然后查找。
代码如下:
#include<stdio.h>#include<iostream>#include<algorithm>using namespace std;typedef struct{    int timecheck[8][12];//由于数据不大,可以开一个二维数组来纪录该学生一星期所有时间    char name[30];}student;typedef struct{    char Lname[30];}Lstudent;student book[201];Lstudent buf[201];bool c(Lstudent a,Lstudent b){    return (strcmp(a.Lname,b.Lname)<0);}int main(){    int n,i,b,t,k,l,x,b1,e1,count;    scanf("%d",&n);    for(i=0;i<n;i++)    {        memset(book, 0, sizeof(book));        memset(buf, 0, sizeof(buf));        scanf("%d",&t);        for(b=0;b<t;b++)        {            scanf("%s",book[b].name);            scanf("%d",&k);            for(l=0;l<k;l++)            {                scanf("%d%d%d",&x,&b1,&e1);                for(int o=b1;o<=e1;o++)                {                    book[b].timecheck[x][o]=1;                    //book[b]代表特定的一个学生,book[b].timecheck[x][o]来表示该学生该段时间是否为空,置1代表忙碌,置0代表空闲                }            }        }        scanf("%d",&k);        for(l=0;l<k;l++)        {            int first=1;            count=0;            scanf("%d%d%d",&x,&b1,&e1);            for(b=0;b<t;b++)            {                for(int o=b1;o<=e1;o++)                {                    if(book[b].timecheck[x][o]==1)//查询发现等于1,则说明这段时间学生为忙碌,和春游相冲突                    {                        strcpy(buf[count].Lname,book[b].name);                        count++;                        break;                    }                }            }            if(count==0)            {                printf("None\n");            }            else            {                sort(buf,buf+count,c);                for(int y=0;y<count;y++)                {                    if(first)                        first=0;                    else                        printf(" ");                    printf("%s",buf[y].Lname);                }                printf("\n");            }        }            }}


0 0
原创粉丝点击