哈理工OJ 1453 AAAAHH! Overbooked!(水题,换思维)

    xiaoxiao2026-08-06  2

    AAAAHH! Overbooked! Time Limit: 1000 MS Memory Limit: 65536 K Total Submit: 41(26 users) Total Accepted: 30(26 users) Rating: Special Judge: No Description Elaine is excited to begin the school year|so excited, in fact, that she signed herself up to attend several events today (This programming contest, sadly, is not one of them). She may have overdone it, though; she didn’t bother to check whether the events she signed up for have con icting times. While you’re sitting here in this contest, why not check for her? Input The input consists of multiple test cases. Each test case begins with an integer N, 1 <= N <= 100, on a line by itself denoting the number of events. After that follow N lines giving the start and end times of each event, in hh:mm-hh:mm 24-hour format. The end time is guaranteed to be strictly after the start time. Input is followed by a single line with N = 0, which should not be processed.

    For example:

    3

    09:00-09:50

    13:00-17:00

    09:50-10:30

    2

    10:00-11:00

    09:00-12:00

    0

    Output For each test case, print out a single line that says \conflict” (no quotes) if Elaine’s events have conflicting times, and \no conflict” (no quotes) otherwise. Assume that Elaine can travel around campus instantaneously, so if an event starts at the same time another event ends, the two events do not conflict.

    For example:

    no conflict

    conflict

    Sample Input 3

    09:00-09:50

    13:00-17:00

    09:50-10:30

    2

    10:00-11:00

    09:00-12:00

    0

    Sample Output no conflict

    conflict

    Source 2010 Stanford Local ACM Programming Contest

    其实这道题只需要换下思维就好了,把时间改成一个四位数。 然后sort一下,看有没有相交区间就好了。 下面是AC代码:

    #include<cstdio> #include<cstring> #include<algorithm> using namespace std; struct node { int st,en; }a[1005]; bool cmp(node x,node y) { return x.st<y.st; } int main() { int n; while(~scanf("%d",&n)) { if(n==0) { break; } char s[30]; for(int i=0;i<n;i++) { scanf("%s",s); a[i].st=(s[0]-'0')*1000+(s[1]-'0')*100+(s[3]-'0')*10+s[4]-'0'; a[i].en=(s[6]-'0')*1000+(s[7]-'0')*100+(s[9]-'0')*10+s[10]-'0'; } int flag=0; sort(a,a+n,cmp); for(int i=1;i<n;i++) { if(a[i].st<a[i-1].en) { flag=1; break; } } if(flag==1) { printf("conflict\n"); } else { printf("no conflict\n"); } } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1310921.html
    最新回复(0)