日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5091】Beam Cannon(线段树,扫描线)

發布時間:2023/12/10 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5091】Beam Cannon(线段树,扫描线) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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 spaceships is approaching. There is a very large Beam Cannon on the Planet X, and it is very powerful, which can destroy all the spaceships in its attack range in a second. However, it takes a long time to fill the energy of the Beam Cannon after each shot. So, you should make sure each shot can destroy the enemy spaceships as many as possible.?

To simplify the problem, the Beam Cannon can shot at any area in the space, and the attack area is rectangular. The rectangle parallels to the coordinate axes and cannot rotate. It can only move horizontally or vertically. The enemy spaceship in the space can be considered as a point projected to the attack plane. If the point is in the rectangular attack area of the Beam Cannon(including border), the spaceship will be destroyed.

Input

Input contains multiple test cases. Each test case contains three integers N(1<=N<=10000, the number of enemy spaceships), W(1<=W<=40000, the width of the Beam Cannon’s attack area), H(1<=H<=40000, the height of the Beam Cannon’s attack area) in the first line, and then N lines follow. Each line contains two integers x,y (-20000<=x,y<=20000, the coordinates of an enemy spaceship).?

A test case starting with a negative integer terminates the input and this test case should not to be processed.

Output

Output the maximum number of enemy spaceships the Beam Cannon can destroy in a single shot for each case.

Sample Input

2 3 4 0 1 1 0 3 1 1 -1 0 0 1 1 0 -1

Sample Output

2 2

題目大意:

? 給你一個矩形的寬度和長度,然后給你一些點的坐標,讓你輸出這個矩形最多能覆蓋多少個點。

解題報告:

? 類似掃描線的思想,將一條邊拆成兩條邊,權值分別為1和-1。

AC代碼1:(其實這里的.f,用laz比較合適)

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair using namespace std; const int MAX = 2e5 + 5; struct Node {int x,y;int f;bool operator < (const Node &a)const{if(y==a.y) return f<a.f;return y<a.y;} } node[MAX]; struct TREE {int l,r;int f,val; } tree[400005 * 16];//??????????????????? void pushdown(int cur) {if(tree[cur].f == 0) return;int tmp = tree[cur].f;tree[cur].f = 0;tree[cur*2].f += tmp;tree[cur*2+1].f += tmp;tree[cur*2].val += tmp;tree[cur*2+1].val += tmp; } void build(int l,int r,int cur) {tree[cur].l=l,tree[cur].r=r;tree[cur].f = tree[cur].val = 0;if(l == r) return;int m = (l+r)>>1;build(l,m,cur*2);build(m+1,r,cur*2+1); } void update(int pl,int pr,int val,int cur) {if(pl <= tree[cur].l && pr >= tree[cur].r) {//pushup(cur);tree[cur].f += val;tree[cur].val += val;return ;}pushdown(cur);if(tree[cur*2].r >= pl) update(pl,pr,val,cur*2);if(tree[cur*2+1].l <= pr) update(pl,pr,val,cur*2+1);//pushup(cur);tree[cur].val = max(tree[cur*2].val,tree[cur*2+1].val); } int main() {int n,W,H;while(cin>>n) {if(n == -1) break;cin>>W>>H;for(int a,b,i = 1; i<=2*n; i+=2) {scanf("%d%d",&a,&b);a+=20005;node[i].x=a;node[i+1].x=a;node[i].y=b;node[i+1].y=b+H+1;node[i].f=1;node[i+1].f=-1;}sort(node+1,node+2*n+1);build(1,10005*8,1);int ans = 0;for(int i = 1; i<=2*n; i++) {update(node[i].x,node[i].x + W,node[i].f,1);ans = max(ans,tree[1].val);}printf("%d\n",ans); }return 0 ; }

AC代碼3:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair using namespace std; const int MAX = 2e5 + 5; struct Node {int x,y;int f;bool operator < (const Node &a)const{return x<a.x;} } node[MAX]; struct TREE {int l,r;int f,val; } tree[400005 * 16];//??????????????????? void pushdown(int cur) {if(tree[cur].f == 0) return;int tmp = tree[cur].f;tree[cur].f = 0;tree[cur*2].f += tmp;tree[cur*2+1].f += tmp;tree[cur*2].val += tmp;tree[cur*2+1].val += tmp; } void build(int l,int r,int cur) {tree[cur].l=l,tree[cur].r=r;tree[cur].f = tree[cur].val = 0;if(l == r) return;int m = (l+r)>>1;build(l,m,cur*2);build(m+1,r,cur*2+1); } void update(int pl,int pr,int val,int cur) {if(pl <= tree[cur].l && pr >= tree[cur].r) {//pushup(cur);tree[cur].f += val;tree[cur].val += val;return ;}pushdown(cur);if(tree[cur*2].r >= pl) update(pl,pr,val,cur*2);if(tree[cur*2+1].l <= pr) update(pl,pr,val,cur*2+1);//pushup(cur);tree[cur].val = max(tree[cur*2].val,tree[cur*2+1].val); } int main() {int n,W,H;while(cin>>n) {if(n == -1) break;cin>>W>>H;for(int a,b,i = 1; i<=2*n; i+=2) {scanf("%d%d",&a,&b);b+=20000;node[i].x=a;node[i+1].x=a+W+1;node[i].y=b;node[i+1].y=b;node[i].f=1;node[i+1].f=-1;}sort(node+1,node+2*n+1);build(0,10005*8,1);int ans = 0;for(int i = 1; i<=2*n; i++) {update(node[i].y,node[i].y + H,node[i].f,1);ans = max(ans,tree[1].val);}printf("%d\n",ans); }return 0 ; }

AC代碼4:(其實排序來說最標準的應該是這樣)

struct Node {int x,y;int f;bool operator < (const Node &a)const{if(x==a.x) return f<a.f;return x<a.x;} } node[MAX];

?

總結

以上是生活随笔為你收集整理的【HDU - 5091】Beam Cannon(线段树,扫描线)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。