[线段树]HDU5091 Beam Cannon

题意:给n, w, h  (1 < = N < = 10000, 1 < = W < = 40000, 1 < = H < = 40000)

  w*h是可以射到的范围

 然后给n个点的坐标x, y (-20000 < = x,y < = 20000)

问 射一次 能射到几个点.

很裸的扫描线线段树

这么水的题不知为何在现场没有写啊??????

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <cstring>
  4 #include <climits>
  5 #include <cctype>
  6 #include <cmath>
  7 #include <string>
  8 #include <sstream>
  9 #include <iostream>
 10 #include <algorithm>
 11 #include <iomanip>
 12 using namespace std;
 13 #include <queue>
 14 #include <stack>
 15 #include <vector>
 16 #include <deque>
 17 #include <set>
 18 #include <map>
 19 typedef long long LL;
 20 typedef long double LD;
 21 #define pi acos(-1.0)
 22 #define lson l, m, rt<<1
 23 #define rson m+1, r, rt<<1|1
 24 typedef pair<int, int> PI;
 25 typedef pair<int, PI> PP;
 26 #ifdef _WIN32
 27 #define LLD "%I64d"
 28 #else
 29 #define LLD "%lld"
 30 #endif
 31 //#pragma comment(linker, "/STACK:1024000000,1024000000")
 32 //LL quick(LL a, LL b){LL ans=1;while(b){if(b & 1)ans*=a;a=a*a;b>>=1;}return ans;}
 33 //inline int read(){char ch=‘ ‘;int ans=0;while(ch<‘0‘ || ch>‘9‘)ch=getchar();while(ch<=‘9‘ && ch>=‘0‘){ans=ans*10+ch-‘0‘;ch=getchar();}return ans;}
 34 //inline void print(LL x){printf(LLD, x);puts("");}
 35 //inline void read(double &x){char c = getchar();while(c < ‘0‘) c = getchar();x = c - ‘0‘; c = getchar();while(c >= ‘0‘){x = x * 10 + (c - ‘0‘); c = getchar();}}
 36
 37 const int maxn = 100005;
 38 int X[maxn<<3];
 39 struct Seg
 40 {
 41     int h , l , r, s;
 42     Seg() {}
 43     Seg(int a,int b,int c,int d) : l(a) , r(b) , h(c) , s(d) {}
 44     bool operator < (const Seg &cmp) const
 45     {
 46         return h < cmp.h;
 47     }
 48 } ss[maxn<<3];
 49 int len[maxn<<3],cnt[maxn<<3];
 50 void PushUp(int rt)
 51 {
 52     len[rt]=max(len[rt<<1], len[rt<<1|1]);
 53 }
 54 void PushDown(int rt)
 55 {
 56     if(cnt[rt])
 57     {
 58         cnt[rt<<1]+=cnt[rt];
 59         cnt[rt<<1|1]+=cnt[rt];
 60         len[rt<<1]+=cnt[rt];
 61         len[rt<<1|1]+=cnt[rt];
 62         cnt[rt]=0;
 63     }
 64 }
 65 void Update(int L, int R, int c, int l , int r, int rt)
 66 {
 67     if(L<=l && r<=R)
 68     {
 69         cnt[rt]+=c;
 70         len[rt]+=c;
 71         return ;
 72     }
 73 //    PushDown(rt);
 74     int m=(l+r)>>1;
 75     if(L<=m)
 76         Update(L, R, c, lson);
 77     if(m<R)
 78         Update(L, R, c, rson);
 79 //    PushUp(rt);
 80     len[rt]=max(len[rt<<1], len[rt<<1|1])+cnt[rt];
 81 }
 82 int main()
 83 {
 84 #ifndef ONLINE_JUDGE
 85     freopen("in.txt", "r", stdin);
 86     freopen("out.txt", "w", stdout);
 87 #endif
 88     int n;
 89     while(~scanf("%d", &n))
 90     {
 91         if(n<0)
 92             break;
 93         int w, h;
 94         scanf("%d%d", &w, &h);
 95         int m=0;
 96         while(n--)
 97         {
 98             int a, b;
 99             scanf("%d%d", &a, &b);
100             X[m]=a;
101             ss[m++]=Seg(a, a+w, b, 1);
102             X[m]=a+w;
103             ss[m++]=Seg(a, a+w, b+h, -1);
104         }
105         sort(X, X+m);
106         sort(ss, ss+m);
107         int k=unique(X, X+m)-X;
108         int ans=0;
109         memset(len, 0, sizeof(len));
110         memset(cnt, 0, sizeof(cnt));
111         for(int i=0;i<m;i++)
112         {
113             int l=lower_bound(X, X+k, ss[i].l)-X;
114             int r=lower_bound(X, X+k, ss[i].r)-X;
115             Update(l, r, ss[i].s, 0, k-1, 1);
116             ans=max(ans, len[1]);
117         }
118         printf("%d\n", ans);
119     }
120     return 0;
121 }

HDU5091

  

时间: 2024-12-13 05:57:04

[线段树]HDU5091 Beam Cannon的相关文章

HDU5091 Beam Cannon(线段树扫描线)

#include<cstdio> #include<cstring> #include<vector> #include<algorithm> using namespace std; const int maxn=40005; const int bw=20000; #define lson(x) ((x)<<1) #define rson(x) (((x)<<1)|1) int lc[maxn<<2],rc[maxn&

线段树+扫描线 HDOJ 5091 Beam Cannon

题目传送门 1 /* 2 题意:给出若干个点的坐标,用一个矩形去覆盖,问最多能覆盖几个点 3 线段树+扫描线:思路是先建一棵以[y, y + h]的树,左右儿子[x, x + w] 4 以这棵树为范围,从左到右扫描,更新点数,x的+1, x+w的-1(超过矩形范围) 5 ans = 每次更新时所覆盖点数的最大值 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <iostream> 10 #includ

hdu 5091 Beam Cannon 离散化+扫描线+线段树

Beam Cannon Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 551    Accepted Submission(s): 207 Problem Description Recently, the γ galaxies broke out Star Wars. Each planet is warring for resou

[POI 2001+2014acm上海邀请赛]Gold Mine/Beam Cannon 线段树+扫描线

Description Byteman, one of the most deserving employee of The Goldmine of Byteland, is about to retire by the end of the year. The Goldmine management would like to reward him in acknowledgment of his conscientious work. As a reward Byteman may rece

hdu 5091 Beam Cannon(线段树扫描线)

题目链接:hdu 5091 Beam Cannon 题目大意:给定N个点,现在要有一个W?H的矩形,问说最多能圈住多少个点. 解题思路:线段的扫描线,假设有点(x,y),那么(x,y)~(x+W,y+H)形成的矩形,以框的右下角落的位置是可以圈住(x,y) 点,所以N个点即为N个矩形,求覆盖的最大次数,扫描线裸题. #include <cstdio> #include <cstring> #include <vector> #include <algorithm&

hdu 5091 Beam Cannon(线段树+扫描线+离散化)

Beam Cannon Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 457    Accepted Submission(s): 175 Problem Description Recently, the γ galaxies broke out Star Wars. Each planet is warring for resou

HDU 5091---Beam Cannon(线段树+扫描线)

题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5091 Problem Description Recently, the γ galaxies broke out Star Wars. Each planet is warring for resources. In the Star Wars, Planet X is under attack by other planets. Now, a large wave of enemy spaces

hdu5091 线段树

题意: 给了n个点在平面中 n<10000  然后 将这给了一个 宽为W 高为 H 的 矩形, 然后 使得这个矩形可以 涵盖最多的点有多少个,然后矩形的宽平行x 轴高平行y轴.可以将该矩形 水平或者上下移动,求他说能选中最多 多少个点,通过扫面线枚举每个x值的点 从小到大 ,选定区间后,将每个点的y值进行离散,然后以每个y为开始的点 分成 上下 的 区间 k个,然后建立一个 1到k 的 线段树, 对于每次选举的x 区间 操作这颗线段树, 因为我们知道 , 对与 一个 y 他可能属于很多的区间,

HDOJ 5091 Beam Cannon 扫描线

线段树+扫描线: 我们用矩形的中心点来描述这个矩形,然后对于每个敌舰,我们建立一个矩形中心的活动范围,即矩形中心在该范围内活动就可以覆盖到该敌舰.那么我们要求的问题就变成了:任意一个区域(肯定也是矩形的)最多能被矩形覆盖的最大值. Beam Cannon Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 159    Accepted S