Main topic
Give some cows, a person at the origin of the observation, cattle and cows and the relationship between each other, give the way and location of each cow, ask how many cows the person will eventually see.
Ideas
Knowing the way of operation, we know that the cow in what time period will block people's sight, and then from high to low to get something to maintain the coverage of what, this problem becomes POJ's mayor ' s posters.
Pay attention to the difference between the point of time and the time period.
CODE
#define _crt_secure_no_warnings#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MAX 100010using namespace STD;#define LEFT (POS << 1)#define RIGHT (pos << 1|1)structcow{intX,y,c;intst,ed;BOOL operator< (ConstCow &a)Const{returny > a.y; }voidRead () {scanf("%d%d%d", &x, &y, &c); X *=-1; St = c * (X-1); ed = st + C; }}src[max];intcows;pair<int,int*> Xx[max <<1];intCnt,t;intTree[max <<4];inline voidPushdown (intPOS) {if(Tree[pos]) {Tree[left] = Tree[pos]; Tree[right] = Tree[pos]; Tree[pos] =0; }}voidModify (intLintRintXintYintCintPOS) {if(L = = x && y = = r) {Tree[pos] = C;return; } pushdown (POS);intMid = (L + r) >>1;if(Y <= mid) Modify (L, Mid, X, Y, C, left);Else if(X > Mid) Modify (Mid +1, R, X, Y, C, right);Else{Modify (L, Mid, X, Mid, C, left); Modify (Mid +1, R, Mid +1, Y, C, right); }}inline intAsk (intLintRintXintPOS) {if(L = = r)returnTree[pos]; Pushdown (POS);intMid = (L + r) >>1;if(x <= mid)returnAsk (L, Mid, X, left);returnAsk (Mid +1, R, X, right);}BOOLV[max];intMain () {Cin>> cows; for(inti =1; I <= cows; ++i) Src[i]. Read (); Sort (src +1, src + cows +1); for(inti =1; I <= cows; ++i) {xx[++cnt] = Make_pair (Src[i].st, &src[i].st); XX[++CNT] = Make_pair (Src[i].ed, &src[i].ed); } sort (xx +1, XX + cnt +1); for(inti =1; I <= CNT; ++i) {if(i = =1|| Xx[i].first! = xx[i-1].first) T + =2; *xx[i].second = t; } for(inti =1; I <= cows; ++i) Modify (1, T, Src[i].st, Src[i].ed, I,1); for(inti =1; I <= t; ++i) V[ask (1, T, I,1)] =true;intAns =0; for(inti =1; I <= cows; ++i) ans + = v[i];cout<< ans << Endl;return 0;}
Bzoj 3888 Usaco Jan Stampede Simulation