The main topic: there is a MC, to host n wedding, give the wedding start time and end time, each wedding needs more than half of the time as a ritual, and the ceremony can not be terminated. Ask the MC If he can host n wedding.
Problem-solving ideas: greedy, in order to try to host more weddings, every ritual time must be as short as possible d = (T-s)/2 + 1, (because must be greater than half, so add 1). Then according to each wedding can be at the latest end of the time to sort t-d, (because to meet all the wedding, so as far as possible to solve the early ritual, make time to give back to the wedding), maintenance of a time-consuming value can be.
#include <cstdio>#include <algorithm>using namespace STD;structWedding {intS, T, D;BOOL operator< (Constwedding& a)Const{returnt-d < A.T-A.D; }} w[100010];BOOLJudgeintN) {intCur =0; for(inti =0; i < N; i++) {cur = max (cur, w[i]. S) + w[i]. Dif(cur > W[i]. Treturn false; }return true;}intMain () {intN while(scanf("%d", &n) && N) { for(inti =0; i < N; i++) {scanf("%d%d", &w[i]. S, &w[i]. S) \ W[i]. D = (W[i]. T-w[i]. S)/2+1; } sort (W, W + N);printf("%s\n", judge (N)?"YES":"NO"); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
UVA-1420 priest John ' s busiest day