會場的安排

上來沒多想,用起始時間排序,處理,打印,測試數據通過,運行wa

自己模擬數據:

0-15

2-3

5- 9 

10- 11

這樣就只能安排一場,尷尬,趕緊用結束時間排

2-3

5-9

10-11

0-15

正解。。。。。。恥辱

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;

    struct node{
        int s;
        int e;
    }a[10001];

    bool cmp(struct node x,struct node y ){
        return x.e<y.e;
    }

    int main(){
        int n,m;
        int count;
        scanf("%d",&n);
        while(n--){
            count = 1;
            memset(a,0,sizeof(a));
            scanf("%d",&m);
            for(int i=0 ;i<m ; i++){
                scanf("%d %d",&a[i].s,&a[i].e);
                if(a[i].s>a[i].e){
                    int temp = a[i].s;
                    a[i].s = a[i].e;
                    a[i].e = temp;
                }
            }
            sort(a,a+m,cmp);
            int flag = a[0].e;
            for(int i=1 ;i<m ; i++){
                if(a[i].s > flag){
                    count++;
                    flag = a[i].e;
                }
            }
            printf("%d\n",count);
        }


    }




發佈了91 篇原創文章 · 獲贊 6 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章