HDU 5857 Median
因为原序列是排列好了的,那么只要看一下给出的两个区间相交的情况,然后分类讨论一下,O(1)输出。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int maxn=;
int T,n,m,a[maxn]; int get(int l1,int r1,int l2,int r2 ,int x)
{
if(l2>r1)
{
if(r1-l1+>=x) return a[l1+x-];
else return a[l2+x-(r1-l1+)-];
} else if(r2<=r1)
{
if(l2-l1>=x) return a[l1+x-];
else if(*(r2-l2+)+l2-l1>=x) return a[l2+(x-(l2-l1)-)/];
else return a[r2++x-(*(r2-l2+)+l2-l1)-];
} else
{
if(l2-l1>=x) return a[l1+x-];
else if(*(r1-l2+)+l2-l1>=x) return a[l2+(x-(l2-l1)-)/];
else return a[r1++x-(*(r1-l2+)+l2-l1)-];
}
} int main()
{
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=m;i++)
{
int l1,r1,l2,r2;
scanf("%d%d%d%d",&l1,&r1,&l2,&r2);
if(l1>l2) { swap(l1,l2); swap(r1,r2); }
if((r1-l1++r2-l2+)%==)
{
printf("%.1lf\n",1.0*get(l1,r1,l2,r2,(r1-l1++r2-l2+)/+));
}
else
{
double num1=1.0*get(l1,r1,l2,r2,(r1-l1++r2-l2+)/);
double num2=1.0*get(l1,r1,l2,r2,(r1-l1++r2-l2+)/+);
printf("%.1lf\n",1.0*(num1+num2)/2.0);
}
}
}
return ;
}
HDU 5857 Median的更多相关文章
- HDU 5857 Median (推导)
Median 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5857 Description There is a sorted sequ ...
- hdu 3648 Median Filter (树状数组)
Median Filter Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU5857 Median 模拟
Median HDU - 5857 There is a sorted sequence A of length n. Give you m queries, each one contains fo ...
- hdu 3282 Running Median
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 Running Median Description For this problem, you ...
- HDU 4981 Goffi and Median(水)
HDU 4981 Goffi and Median 思路:排序就能够得到中间数.然后总和和中间数*n比較一下就可以 代码: #include <cstdio> #include <c ...
- HDU 3282 Running Median 动态中位数,可惜数据范围太小
Running Median Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 4981 Goffi and Median
题解:排序取中位数,然后与平均数比较即可. #include <cstdio> #include <algorithm> using namespace std; double ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- hdu 4908(思路题)
BestCoder Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- 【Zookeeper】源码分析之Watcher机制(二)
一.前言 前面已经分析了Watcher机制中的第一部分,即在org.apache.zookeeper下的相关类,接着来分析org.apache.zookeeper.server下的WatchManag ...
- .NET 基础 一步步 一幕幕[面向对象之堆、栈、引用类型、值类型]
堆.栈.引用类型.值类型 内存分为堆和栈(PS:还有一种是静态存储区域 [内存分为这三种]),值类型的数据存储在栈中,引用类型的数据存储在堆中. 堆.栈: 堆和栈的区别: 栈是编译期间就分配好的内存空 ...
- 怎样在linux或者Unix上检查端口是否在使用
英文原文链接:https://www.cyberciti.biz/faq/unix-linux-check-if-port-is-in-use-command/ Question 1: 怎样在lin ...
- Meterpreter
监听 AutoRunScrip:自动执行脚本 如:自动执行post/windows/manage/migrate set AutoRunScript post/windows/manage/migra ...
- iOS用AFN上传图片到java后台
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { AFHTTPSessionMana ...
- [UWP小白日记-4]记账项目-2
手机端: 待续…… 哈哈这个代码真是好长时间啊,没办法萌新你们都懂的,UI是改了又改,知识也在慢慢积累, 所以这效率就低下了点 UI是改了又改,代码是不断了改,所以搞到现在都没开发完成
- nginx https 配置
1.创建证书并下载(下载完成后有两个文件) *.pem *.key 2.将两个文件放在linux 某个目录下 3.配置nginx的conf配置文件 server{ # https 端口默认不是80,是 ...
- nvl isnull coalesce
oracle 的NVL(col,0)是判断如果col字段为空的时候赋值0. postgresql里也有类似的方法 SELECT coalesce(collect_result,0) as collec ...
- 对xlslib库与libxls库的简易封装
一.简介 xlslib库是用来创建excel文件.libxls是用来读取excel文件的,在使用C++或者QT语言来设计对excel文件的读取.都需要事先下载这两个库编译成功后再进行程序设计的.之所以 ...
- 【IE6的疯狂之八】链接伪类(:hover)CSS背景图片有闪动BUG
IE6下链接伪类(:hover)CSS背景图片有闪动BUG,主要原因ie会再一次请求这张图片,或者说图片没被缓存. 例如: CSS代码 a:hover{background:url(imagepath ...