zoj zju 3597 Hit the Target! 线段树 扫描线
来源:互联网 发布:java 轮询查询数据库 编辑:程序博客网 时间:2024/06/05 18:18
这题很锻炼模型转换的能力http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3597
题意:有一排的枪编号依次为1~n 有一排靶子编号依次为1~m
告诉你哪些枪能打中哪些靶子,然后如果每次只能选连续的P把枪,连续的Q个靶子,每次能打中的靶子的最大值为多少
答案是把每次打中的最大值相加再除以总的次数
即选择 1~P 的枪能打中的最多的靶子的数量 + 2~p+1 的枪能打中的最多的靶子的数量 +。。。n-p+1~n的枪能打中的最多的靶子的数量 /(n-p+1)
注意,每把枪最多只能打一个靶子
解法:将题目中的关系转换为坐标 以枪为纵坐标 a 能打中 b ,在坐标系中为(b,a),然后连续的P把枪和连续的Q个靶子则可以表示为
用一个P x Q的矩形去覆盖,最多能覆盖的总的点数,就是poj 2482 了,但要注意一点,如果两根同一高度的水平线的距离小于Q,则重叠的部分职能算一次,因为每把枪只能打一个靶子
我的代码
View Code
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define lson l,m,x<<1#define rson m+1,r,x<<1|1const int maxn = 100010;int Max[maxn<<2],col[maxn<<2];struct point{ int x,y; bool operator <(const point &cmp) const { return y<cmp.y || (y==cmp.y&&x<cmp.x); }}pp[maxn];inline int max(int a,int b){ return a>b?a:b;}inline int min(int a,int b){ return a<b?a:b;}void pushdown(int x){ if(col[x]){ Max[x<<1]+=col[x]; Max[x<<1|1]+=col[x]; col[x<<1]+=col[x]; col[x<<1|1]+=col[x]; col[x]=0; }}void build(int l,int r,int x){ Max[x]=col[x]=0; if(l==r) return ; int m=(l+r)>>1; build(lson); build(rson);}void update(int L,int R,int val,int l,int r,int x){ if(L<=l&&r<=R){ col[x]+=val; Max[x]+=val; return ; } pushdown(x); int m=(l+r)>>1; if(L<=m) update(L,R,val,lson); if(R>m) update(L,R,val,rson); Max[x]=max(Max[x<<1],Max[x<<1|1]);}void solve(int n,int m,int p,int q,int K){ int i,j,y0; double ret=0; build(1,m,1); i=j=0; for(y0=1;y0+p-1<=n;y0++) { for(;j<K && pp[j].y-y0 < p;j++) { if(j+1 < K && pp[j+1].y==pp[j].y && pp[j+1].x-pp[j].x < q) update(pp[j].x,pp[j+1].x-1,1,1,m,1); else update(pp[j].x,min(m,pp[j].x+q-1),1,1,m,1); } ret+=Max[1]; for(;i<j&&pp[i].y==y0;i++) { if(i+1<j && pp[i+1].y==y0 && pp[i+1].x-pp[i].x < q) update(pp[i].x,pp[i+1].x-1,-1,1,m,1); else update(pp[i].x,min(pp[i].x+q-1,m),-1,1,m,1); } } printf("%.2lf\n",ret/(n-p+1));}int main(){ int t,n,m,p,q,k,i; scanf("%d",&t); while(t--) { scanf("%d%d%d%d%d",&n,&m,&p,&q,&k); for(i=0;i<k;i++) scanf("%d%d",&pp[i].y,&pp[i].x); sort(pp,pp+k); solve(n,m,p,q,k); } return 0;}
- zoj zju 3597 Hit the Target! 线段树 扫描线
- zoj 3597 Hit the Target! (线段树)
- Hit the Target!
- zoj zju 3324 线段树 离散化
- ZJU 1610 Count the Colors 线段树
- hdu 1556 Color the ball (线段树之扫描线)
- HDU 3642 Get The Treasury 【线段树】【扫描线】
- 线段树[扫描线]
- 线段树+扫描线
- 线段树 扫描线
- 线段树扫描线
- 线段树-扫描线
- 非结构体线段树版 ZJU 1610 Count the Colors (线段树区间更新)
- 求大神路过指导ZOJ3597 Hit the Target!
- ZOJ 1610Count the Colors//线段树
- zoj 1610 Count the Colors【线段树】
- zoj 1610 Count the Colors[线段树]
- 【线段树】Count the Colors (zoj 1610)
- poj 1986 RMQ&&LCA( 模板题)
- codeforces 182D Common Divisors KMP做法
- codeforces 182E Wooden Fence 动态规划
- codeforces 115E Linear Kingdom Races 线段树 + DP 好题
- 后缀数组论文推荐题
- zoj zju 3597 Hit the Target! 线段树 扫描线
- zoj zju 3606 Lazy Salesgirl
- Ubuntu APT常用命令参数
- poj 3093 01背包
- codeforces ABBYY Cup 2.0
- codeforces 46D 线段树 区间合并
- CF 12D BALL 线段树 && 树状数组
- hdu 3811 用状态压缩DP 解决看似组合数学的题目
- hdu 3271 数位统计 的 DP