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

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值