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