Uva1420-priest John's busiest day

Source: Internet
Author: User

Question Link

Question:Can Pastor John arrange for all weddings to send a blessing to all weddings (The Blessing time is half the wedding time ).

Ideas: Greedy, sort the wedding period from small to large, and try to end the wedding as early as possible. The last time the wedding blessing starts (each wedding has a Blessing time that begins at the latest) is earlier.


# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; const int maxn = 100005; struct wedding {long S, T, mid, L;} W [maxn]; int N, flag; int CMP (wedding A, wedding B) {return. mid <B. mid;} int solve () {int start = 0; For (INT I = 0; I <n; I ++) {If (Start> W [I]. t-W [I]. l) return false; else if (start <= W [I]. s) Start = W [I]. mid; else start + = W [I]. l;} return true;} int main () {While (scanf ("% d", & N) {for (INT I = 0; I <N; I ++) {scanf ("% LLD", & W [I]. s, & W [I]. t); W [I]. L = (W [I]. t-W [I]. s)/2 + 1; W [I]. mid = W [I]. S + W [I]. l;} Sort (W, W + N, CMP); solve (); If (solve () printf ("Yes \ n "); else printf ("NO \ n");} return 0 ;}

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.