Description
From a point to a straight line, each ordinate can only increase or decrease by 1, some locations have obstacles, to increase the minimum number of steps.
Sol
Greedy.
Maybe it's greedy. Anyway in the reachable range, ordinate as small as possible ...
When doing the maintenance of two endpoints, because in this interval operand monotonically increment, only need to take the bottom point is good.
Code
/************************************************************** problem:4723 User:beiyu language:c++ Result : Accepted time:1884 ms memory:1284 kb****************************************************************/#include < ;cstdio> #include <iostream>using namespace std; #define DEBUG (a) cout<< #a << "=" <<a<< "" int n,m,ans;int x,l,r; int main () {//Freopen ("In.in", "R", stdin); Ios::sync_with_stdio (FALSE); cin>>n>>m; x=l=r=0; for (int i=1;i<=n;i++) {int x,l,r,t; cin>>x>>l>>r; l++,r--; T= (x-x); L=max (L,L-T); R=min (r,r+t); if ((l-l+t) &1) l++; if ((r-r+t) &1) r--; if (l<l-t) ans+= (l-t-l) >>1,L=l-t; if (r>r+t) r=r+t; if (L>r) return puts ("NIE"), 0; ans+= (l-l+t) >>1; cout<< "-----------------"<<i<<"-------------------"<<endl;//debug (x), Debug (L), Debug (R) <<endl;//Debug (x), debug (l), Debug (R) <<endl;//debug (t), Debug (((l-l+t) >>1)) <<endl; L=l; R=r; Y=y; if (L>r) return puts ("NIE"), 0; } cout<<ans<<endl; return 0;}
Bzoj 4723: [Poi2017]flappy Bird