hdu2600 C++

XiaohuangTX發表於2024-07-19

排序一下就ok了

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[30];
struct node
{
    int x;
    int y;
}a[105];
int cmp(node a,node b)
{
    if(a.y!=b.y){
        return a.y<b.y;
    }
    return a.x<b.x;
}
int main()
{
    int n,p,q,b,c;
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%d%d",&p,&q);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
            gets(s);
        }
        sort(a+1,a+n+1,cmp); //按結束時間從小大排序
        if(a[n].y<q)
        {
            printf("%d\n",q);
            continue;
        }
        int res = a[1].x-1;
        int ed = a[1].y;
        for(int i=2;i<=n;i++)
        {
            if(a[i].x>=ed){
                res = a[i].x-1;
            }
            ed = a[i].y;
        }
        if(res<p){
            printf("Badly!\n");
        }else{
            printf("%d\n",res);
        }
    }
    return 0;
}