Codeforces 527D: Brain hole problem

Source: Internet
Author: User

That this kind of topic is totally not

After transforming an expression:

XI+WI<=XJ-WJ (XI<=XJ)

Xj+wj<=xi-wi (XI>=XJ)

I don't think I can see anything--| |

Meet the above Type I J two can hold a regiment, then we have to find as many points as possible to meet the above relationship

In fact, the above two formulas are equivalent (think about it)

So just meet XI+WI<=XJ-WJ's two points to be able to hold the regiment

Then our strategy is greedy, to try to satisfy this formula as much as possible, the smaller the natural xi+wi, the better, so we sort by xi+wi.

The resulting sequence, each element only needs to be judged with the previous element, because how I and i-1 conform to this formula, and the previous point is bound to conform (because we are sorted by Xi+wi, before the point Xi+wi is definitely less than or equal to the current point)

#include"Cstdio"#include"Queue"#include"Cmath"#include"Stack"#include"iostream"#include"algorithm"#include"CString"#include"Queue"#include"Map"#include"Vector"#definell Long Long#defineMEMS (A, B) memset (A,b,sizeof (a))#defineLS pos<<1#defineRS Pos<<1|1using namespacestd;Const intMAXN =200500;Const intMaxe =200500;Const intINF =0x3f3f3f3f;structnn{intw,x;} NODE[MAXN];BOOLcmp (nn a,nn b) {returna.x+a.w<b.w+b.x;}intMain () {intN;SCANF ("%d",&N);  for(intI=0; i<n;i++) scanf ("%d%d",&node[i].x,&NODE[I].W); Sort (Node,node+n,cmp); intans=1; intt=node[0].x+node[0].W;  for(intI=1; i<n;i++){        if(node[i].x-node[i].w>=t) {ans++; T=node[i].x+NODE[I].W; }} cout<<ans<<Endl; return 0;}

Codeforces 527D: Brain hole problem

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.