贪心。。
#include<iostream> #include<string.h> #include<math.h> #include <stdio.h> #include <algorithm> using namespace std; struct node { int s,t; int m; }; node a[100010]; int cmp(node a,node b) { return a.m<b.m; } int main() { int n; int i,j; int now; while(scanf("%d",&n)!=EOF) { if(n==0) break; for(i=0;i<n;i++) { scanf("%d%d",&a[i].s,&a[i].t); if((a[i].t-a[i].s)%2==0) a[i].m=a[i].s+(a[i].t-a[i].s)/2-1; else a[i].m=a[i].s+(a[i].t-a[i].s)/2; } sort(a,a+n,cmp); now=0; int flag=0; int cnt=0; for(i=0;i<n;i++) { if(now>a[i].m) { flag=1; break; } else if(now<=a[i].s) now=a[i].s+(a[i].t-a[i].s)/2+1; else if(now>a[i].s) now=now+(a[i].t-a[i].s)/2+1; cnt++; } if(flag) printf("NO\n"); else { if(cnt==n) printf("YES\n"); else printf("NO\n"); } } return 0; }