UVA-1420 priest John ' s busiest day

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.