Hit the Target!
1.与star in the window 差不多 降维
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
#define LL(x) (x<<1)
#define RR(x) ((x<<1)|1)
int n,m,p,q;
int c;
const int maxn=50005;
struct Seg{
int l,r;
int max;
int flag;
}tree[maxn*4];
void build(int l,int r,int k)
{
tree[k].flag=0;
tree[k].max=0;
tree[k].l=l;
tree[k].r=r;
if(l==r) return ;
int mid=(l+r)>>1;
build(l,mid,LL(k));
build(mid+1,r,RR(k));
}
int Max(int a,int b){
if(a<b) return b;
return a;
}
void push_down(int k)
{
if(tree[k].flag)
{
tree[LL(k)].max+=tree[k].flag;
tree[RR(k)].max+=tree[k].flag;
tree[LL(k)].flag+=tree[k].flag;
tree[RR(k)].flag+=tree[k].flag;
tree[k].flag=0;
}
}
void update(int l,int r,int k,int v)
{
if(l<=tree[k].l && tree[k].r<=r)
{
tree[k].flag+=v;
tree[k].max+=v;
return ;
}
push_down(k);
int mid=(tree[k].l+tree[k].r)>>1;
if(l<=mid) update(l,r,LL(k),v);
if(r>mid) update(l,r,RR(k),v);
tree[k].max=Max(tree[LL(k)].max,tree[RR(k)].max);
}
int main()
{
int T;
int i,j;
int u,v;
double ans;
vector<int>x[maxn];
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d%d",&n,&m,&p,&q);
scanf("%d",&c);
for(i=0;i<=n;i++)
x[i].clear();
for(i=0;i<c;i++)
{
scanf("%d%d",&u,&v);
x[u].push_back(v);
}
build(1,m,1);
ans=0;
for(i=1;i<=n;i++)
{
int a;
sort(x[i].begin(),x[i].end());
for(j=0;j<x[i].size();j++)
{
a=j;
while(a<x[i].size()-1 && x[i][a]+q-1>=x[i][a+1])a++;
if(x[i][a]+q-1>=m)
update(x[i][j],m,1,1);
else
update(x[i][j],x[i][a]+q-1,1,1);
j=a;
}
if(i>p)
{
for(j=0;j<x[i-p].size();j++)
{
a=j;
while(a<x[i-p].size()-1 && x[i-p][a]+q-1>=x[i-p][a+1])a++;
if(x[i-p][a]+q-1>=m)
update(x[i-p][j],m,1,-1);
else
update(x[i-p][j],x[i-p][a]+q-1,1,-1);
j=a;
}
}
if(i>=p)
ans+=tree[1].max;
}
printf("%.2lf\n",ans/(n-p+1));
}
return 0;
}
Hit the Target!相关推荐
- ZOJ 3597 Hit the Target! (线段树扫描线 -- 矩形所能覆盖的最多的点数)
ZOJ 3597 题意是说有n把枪,有m个靶子,每把枪只有一发子弹(也就是说一把枪最多只能打一个靶子), 告诉你第 i 把枪可以打到第j个靶, 现在等概率的出现一个连续的P把枪,在知道这P把枪之后,你 ...
- Ninject依赖注入——构造函数、属性、方法和字段的注入(三)
1.Ninject简介 Ninject是基于.Net平台的依赖注入框架,它能够将应用程序分离成一个个高内聚.低耦合(loosely-coupled, highly-cohesive)的模块,然后以一种 ...
- linux synproxy 抵御 ddos攻击的原理和优化
目录 关于DDoS攻击和本文 关于DDoS与nf_conntrack 附:为什么nf_conntrack表项的查找和创建并不算个事儿 nf_conntrack如何防御DDoS攻击 附:什么是INVAL ...
- 页面置换算法 - FIFO、LFU、LRU
缓存算法(页面置换算法)-FIFO. LFU. LRU 在前一篇文章中通过leetcode的一道题目了解了LRU算法的具体设计思路,下面继续来探讨一下另外两种常见的Cache算法:FIFO. LFU ...
- 编写易于理解代码的六种方式
http://www.ibm.com/developerworks/cn/linux/l-clear-code/ 我学习编写.改善和维护代码的过程是很艰苦的.在过去的 12 年里,我一直在编写计算机游 ...
- Latex论文排版技巧再总结
1.Q:几个作者同时共享机构地址,怎么搞? A:拿ACM的模版为例, Yes, and we suggest you do the following... Insert this piece of ...
- AnswerOpenCV(1001-1007)一周佳作欣赏
外国不过十一,所以利用十一假期,看看他们都在干什么. 一.小白问题 http://answers.opencv.org/question/199987/contour-single-blob-with ...
- kotlin编写后台_在Kotlin编写图书馆的提示
kotlin编写后台 by Adam Arold 亚当·阿罗德(Adam Arold) 在Kotlin编写图书馆的提示 (Tips for Writing a Library in Kotlin) W ...
- vsc 搜索特定代码_特定问题的通用解决方案:何时编写代码以及何时编写代码...
vsc 搜索特定代码 by Rina Artstain 通过丽娜·阿斯特斯坦 特定问题的通用解决方案:何时编写代码以及何时编写代码 (Generic solutions to specific pro ...
最新文章
- elasticsearch 的filter cache (search 技术的冰山一角)
- 白话详细解读(六)----- BiSeNet: Bilateral Segmentation Network for Real-time Semantic Segmentation
- ISO13485 相关
- maven手动安装ojdbc14(oracle jdbc驱动)至本地maven仓库
- Selenium3+MySQL数据库进行数据驱动测试
- 第一届WebRTCon在上海举行
- HTML5知识点汇总
- 2017-9-26 NOIP模拟赛
- 带你从零入门 Serverless | 一文详解 Serverless 架构模式
- 百度——LBS.云 v2.0——云存储的POI创建和删除--Android 源码
- 1079 Total Sales of Supply Chain (25 分) 树的遍历:DFS+vector
- Python:实现Zip格式的文件压缩
- LeetCode-Hot100-寻找两个正序数组的中位数
- codelite14中文语言包_codelite中文版-codelite下载(开源的C++跨平台开发环境) 13.0.7 中文版 - 河东下载站...
- Office EXCEL如何批量把以文本形式存储的数字转换为数字
- 凯利讯的能量收集技术延长电池寿命
- mysql主从同步的三种模式
- Pycharm社区版下载与安装教程
- MySQL错误reading initial communication packet解决办法
- TCP/IP协议族(第4版)