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!相关推荐

  1. ZOJ 3597 Hit the Target! (线段树扫描线 -- 矩形所能覆盖的最多的点数)

    ZOJ 3597 题意是说有n把枪,有m个靶子,每把枪只有一发子弹(也就是说一把枪最多只能打一个靶子), 告诉你第 i 把枪可以打到第j个靶, 现在等概率的出现一个连续的P把枪,在知道这P把枪之后,你 ...

  2. Ninject依赖注入——构造函数、属性、方法和字段的注入(三)

    1.Ninject简介 Ninject是基于.Net平台的依赖注入框架,它能够将应用程序分离成一个个高内聚.低耦合(loosely-coupled, highly-cohesive)的模块,然后以一种 ...

  3. linux synproxy 抵御 ddos攻击的原理和优化

    目录 关于DDoS攻击和本文 关于DDoS与nf_conntrack 附:为什么nf_conntrack表项的查找和创建并不算个事儿 nf_conntrack如何防御DDoS攻击 附:什么是INVAL ...

  4. 页面置换算法 - FIFO、LFU、LRU

    缓存算法(页面置换算法)-FIFO. LFU. LRU 在前一篇文章中通过leetcode的一道题目了解了LRU算法的具体设计思路,下面继续来探讨一下另外两种常见的Cache算法:FIFO. LFU ...

  5. 编写易于理解代码的六种方式

    http://www.ibm.com/developerworks/cn/linux/l-clear-code/ 我学习编写.改善和维护代码的过程是很艰苦的.在过去的 12 年里,我一直在编写计算机游 ...

  6. Latex论文排版技巧再总结

    1.Q:几个作者同时共享机构地址,怎么搞? A:拿ACM的模版为例, Yes, and we suggest you do the following... Insert this piece of ...

  7. AnswerOpenCV(1001-1007)一周佳作欣赏

    外国不过十一,所以利用十一假期,看看他们都在干什么. 一.小白问题 http://answers.opencv.org/question/199987/contour-single-blob-with ...

  8. kotlin编写后台_在Kotlin编写图书馆的提示

    kotlin编写后台 by Adam Arold 亚当·阿罗德(Adam Arold) 在Kotlin编写图书馆的提示 (Tips for Writing a Library in Kotlin) W ...

  9. vsc 搜索特定代码_特定问题的通用解决方案:何时编写代码以及何时编写代码...

    vsc 搜索特定代码 by Rina Artstain 通过丽娜·阿斯特斯坦 特定问题的通用解决方案:何时编写代码以及何时编写代码 (Generic solutions to specific pro ...

最新文章

  1. elasticsearch 的filter cache (search 技术的冰山一角)
  2. 白话详细解读(六)----- BiSeNet: Bilateral Segmentation Network for Real-time Semantic Segmentation
  3. ISO13485 相关
  4. maven手动安装ojdbc14(oracle jdbc驱动)至本地maven仓库
  5. Selenium3+MySQL数据库进行数据驱动测试
  6. 第一届WebRTCon在上海举行
  7. HTML5知识点汇总
  8. 2017-9-26 NOIP模拟赛
  9. 带你从零入门 Serverless | 一文详解 Serverless 架构模式
  10. 百度——LBS.云 v2.0——云存储的POI创建和删除--Android 源码
  11. 1079 Total Sales of Supply Chain (25 分) 树的遍历:DFS+vector
  12. Python:实现Zip格式的文件压缩
  13. LeetCode-Hot100-寻找两个正序数组的中位数
  14. codelite14中文语言包_codelite中文版-codelite下载(开源的C++跨平台开发环境) 13.0.7 中文版 - 河东下载站...
  15. Office EXCEL如何批量把以文本形式存储的数字转换为数字
  16. 凯利讯的能量收集技术延长电池寿命
  17. mysql主从同步的三种模式
  18. Pycharm社区版下载与安装教程
  19. MySQL错误reading initial communication packet解决办法
  20. TCP/IP协议族(第4版)

热门文章

  1. 基础——DB9九孔母头、九针公头 (RS232)接口定义
  2. 仿芒果TV微信小程序源码
  3. 宏基Acer笔记本预装win8系统换成win7系统安装教程
  4. 知道怎样读书和选书?
  5. Microsoft Visual Studio 2012正式版官方下载
  6. session的删除
  7. spring session通过redis存储,实现session共享
  8. 2016,不忘初心;2017,方得始终!
  9. 什么是快照回档?快照回档的原因和解决办法有哪些
  10. 图技术助力汽车制造业解锁数据新价值