今年暑假不AC

Description

“今年暑假不AC?”

“是的。”

“那你干什么呢?”

“看世界杯呀,笨蛋!”

“@#$%^&*%…”

确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。
作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)

input

输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。

ouput

对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。

Sample Input

12
1 3
3 4
0 7
3 8
15 19
15 20
10 15
8 18
6 12
5 10
4 14
2 9
0

Sample Output

5

代码

//
//  main.c
//  潜伏
//
//  Created by ailuoku6 on 2018/10/19.
//  Copyright © 2018年 ailuoku6. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int start;
    int end;
}jiemu;

void sort(jiemu* *arr,int n){
    jiemu *temp;
    for (int i = 0; i < n-1; ++i) {
        for (int j = 0; j < n-1-i; ++j){
            if(arr[j]->start>arr[j+1]->start){
                temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            } else if(arr[j]->start==arr[j+1]->start&&arr[j]->end>arr[j+1]->end){
                temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }

}

int main(int argc, const char * argv[]) {
    // insert code here...
    int t,count;
    jiemu* arr[101];
    int temp;
    while (scanf("%d",&t),t){
        count = 1;
        for (int i = 0; i < t; ++i) {
            jiemu *p = (jiemu *)malloc(sizeof(jiemu));
            scanf("%d %d",&p->start,&p->end);
            arr[i] = p;
        }
        sort(arr,t);
        temp = arr[0]->end;
        for (int j = 1; j < t; ++j) {
            if(arr[j]->start>=temp){
                count++;
                temp = arr[j]->end;
            } else if(arr[j]->end<temp){
                temp = arr[j]->end;
            }
        }
        printf("%d\n",count);
    }
    return 0;
}

今年暑假不AC
http://blog.ailuoku6.top/2018/11/18/jin-nian-shu-jia-bu-ac/
作者
ailuoku6
发布于
2018年11月18日
许可协议