"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)