HDU 5091 Beam Cannon

Source: Internet
Author: User

Test instructions: Move a rectangle so that the rectangle contains as many points as possible.

Idea: Split a point into two events, one in (weighted to 1) one out (weighted to 1), all points sorted by X, then scanned, for each X, a sliding window to calculate the maximum value, and then move the scan line. A tree-like array can be implemented.

The above method is not optimal, and the best known approach is to compress a rectangle into a single point, and a point to extend to a line and update the Y+h interval when encountering a point. (Segment Tree lazy operation), then ask for the maximum value of the point (rectangle) on the line segment tree. You must use a line segment tree to reduce the complexity of the time.

Similar ideas to the topic Seoul2007 La3905,meteor Meteor

Only the tree-shaped array version is written, given that the scan line needs to be further studied and treated more.

At that time do know is a line tree, unfortunately I do not write scan line, previously tried to write, hang, the foundation needs to be strengthened.

#include <cstdio>#include<algorithm>using namespacestd;Const intMaxh =40000+5;Const intMAXN =10000+5;intC[maxh];#defineLowbit (x) (x& (×))voidAddintXintv) {     while(x <=40001) {C[x]+ = V; X + =lowbit (x); }}intSumintx) {    intres =0;  while(x>0) {res+ = C[x]; X-=lowbit (x); }    returnRes;}structpoint{intx, y; BOOL operator< (ConstPoint & RHS)Const {        returnX <rhs.x; }}POI[MAXN];intMain () {//freopen ("In.txt", "R", stdin);    intN;  while(~SCANF ("%d", &n) && n>0){        intw,h; scanf ("%d%d",&w,&H);  for(inti =0; i < N; i++) {scanf ("%d%d",&poi[i].x,&poi[i].y); Poi[i].y+=20001; } sort (Poi,poi+N); intL, R; L = R =0; intAns =0;  while(r<N) {             while(poi[r].x-poi[l].x <= W && r<o) {Add (Poi[r++].Y,1); }             for(inti =1, Sz =40001H I <= sz; i++) {ans= Max (Ans,sum (i+h)-sum (i-1)); }            if(r<N) while(Poi[r].x-poi[l].x >W) {Add (Poi[l++].y,-1); }} printf ("%d\n", ans);  while(l<N) {Add (Poi[l++].y,-1); }    }    return 0;}

HDU 5091 Beam Cannon

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.