# 运动会

输入包括1+N行 第一行输入一个整数N, 1 <= N <= 10，表示今天要参加多少个讨论会 后续N行，每行输入开始和结束时间，均为整数，用空格分隔，0 <= startTime < endTime <= 24

输出包括一行 如果小红能够参加全部讨论会，返回1 如果小红不能够参加全部讨论会，返回-1

3
3 10
1 5
4 6

1


#include<stdio.h>
#include<algorithm>
using namespace std;
struct Node{
int start_time;
int last_start_time;
int halftime;
};

Node nodes[15];

bool cmp(const Node &a,const Node &b){
if(a.last_start_time!=b.last_start_time)
return a.last_start_time<b.last_start_time;
return a.start_time<b.start_time;
}

int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
int start_time,end_time;
scanf("%d%d",&start_time,&end_time);
int halftime=end_time-start_time;
if(halftime==2){
halftime=2;
}
else if(halftime==3){
halftime=2;
}
else if(halftime==4){
halftime=3;
}
else{
if(halftime%2==0)
halftime=halftime/2;
else
halftime=(halftime+1)/2;
}
nodes[i].start_time=start_time;
nodes[i].last_start_time=end_time-halftime;
nodes[i].halftime=halftime;
}
sort(nodes,nodes+n,cmp);
int ok_time=nodes[0].start_time;
int tag=1;
for(int i=0;i<n;i++){
ok_time=max(ok_time,nodes[i].start_time);

if(ok_time<=nodes[i].last_start_time){
ok_time=ok_time+nodes[i].halftime;
}
else{
tag=0;
break;
}
}
if(tag==1)
printf("1\n");
else{
printf("-1\n");
}

}

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客