Codeforces 545CWoodcutters (greedy ordp)

Source: Internet
Author: User

"Topic link": Click here~~

"To the effect of the topic":

There are n trees, give the position and height of each tree, then cut the tree down, and the tree can be left upside down or right. The output can cut up to a few trees.
"Thinking": the use of greedy ideas. The left side of the first tree and the last tree have no trees on the right, so they pour to both sides, then to the middle of the tree, first to the left, and then to the left if not enough to the right to pour, when the right to pay attention to update the distance.

Code:

/  * * problem:codeforces 545c* Running time:46ms  * complier:g++  * Author:herongwei * Create time:7:59 2015 /9/17 Thursday */  #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm >using namespace Std;typedef long long ll;const int n=1e5+100;const int inf=0x7f7f7f7f;struct node{    int codx,heg;< c5/>//coordinate and height    bool ck;} arr[n];int Main () {    int t,n,m;    scanf ("%d", &t);    for (int i=1; i<=t; ++i) {        scanf ("%d%d", &ARR[I].CODX,&ARR[I].HEG);    }    Arr[0].codx=-inf; Init    Arr[t+1].codx=inf;    int s=0;    for (int i=1, i<=t; ++i) {  //left         if (arr[i].codx-arr[i].heg>arr[i-1].codx) {             ++s;             Continue;         }         if (ARR[I].CODX+ARR[I].HEG<ARR[I+1].CODX) {//right             ++s;             Arr[i].codx+=arr[i].heg;         }    }    printf ("%d\n", s);    return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 545CWoodcutters (greedy ordp)

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.