# "HDU 5091" Beam Cannon (scan line)

Source: Internet
Author: User

According to the x-axis, we find the maximum interval of the segment tree.

The model transformation is: matrix maximum intersection

`#include <cstdio> #include <cstring> #include <algorithm>using namespace std; #define Lson (pos<    <1) #define RSON (pos<<1|1) const int ADD = 25555;const int maxn = 80005;int n,w,h,cnt;struct seg{int l,r,h,c;    Seg (int l = 0,int r = 0,int h = 0,int c = 0): L (L), R (R), H (H), C (c) {};    friend bool operator < (Seg p,seg q) {return p.h < q.h; }}ss[maxn];int col[maxn << 2],max_value[maxn << 2];void pushdown (int pos) {if (Col[pos]) {Col[lson] +        = Col[pos];        Max_value[lson] + = Col[pos];        Col[rson] + = Col[pos];        Max_value[rson] + = Col[pos];    Col[pos] = 0; }}void pushup (int pos) {Max_value[pos] = max (Max_value[lson],max_value[rson]);}        void update (int l,int r,int l,int r,int Pos,int v) {if (L <= l && R <= R) {Col[pos] + = V;        Max_value[pos] + = V;    Return    } pushdown (POS);    int mid = (L + R) >> 1;    if (l <= mid) update (L,MID,L,R,LSON,V); if (R >MID) Update (mid + 1,r,l,r,rson,v); Pushup (POS);}        int main () {while (scanf ("%d", &n) && n > 0) {scanf ("%d%d", &w,&h);        CNT = 0;        memset (col,0,sizeof (col));        memset (max_value,0,sizeof (max_value));        int x, y;            for (int i = 0; i < n; i++) {scanf ("%d%d", &x,&y);            x + = ADD;            Y + = ADD;            ss[cnt++] = Seg (x,x + w,y,1);        ss[cnt++] = Seg (x,x + w,y + h,-1);        } sort (Ss,ss + cnt);        int ans = 0;            for (int i = 0; i < cnt; i++) {int L = Ss[i].l,r = Ss[i].r,c = ss[i].c;            Update (0,MAXN,L,R,1,C);        ans = max (ans,max_value[1]);    } printf ("%d\n", ans); } return 0;}`

"HDU 5091" Beam Cannon (scan line)

Related Keywords:

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.