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 ...
随机推荐
- 我的 MarkDown 学习笔记
MarkDown 一种用于写作的轻量级[标记语言].它用简洁的语法代替排版,而不像一般的文字处理软件 Word 或者 Pages 有大量的排版.字体设置等. 如果你对文章的样式没有太多要求,只注重写文 ...
- jQuery 效果 - fadeTo() 方法
实例 使用淡出效果来隐藏一个 <p> 元素: $(".btn1").click(function(){ $("p").fadeTo(1000,0.4 ...
- # 关于string
关于string 头文件 #include <string> using std::string; string定义和初始化 string s1; string s2(s1); strin ...
- nyoj 592 spiral grid(广搜)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=592 解决以下问题后就方便用广搜解: 1.将数字坐标化,10000坐标为(0,0),这样就 ...
- linux下如何查询jdk安装路径
1:echo $JAVA_HOME 使用$JAVA_HOME的话能定位JDK的安装路径的前提是配置了环境变量$JAVA_HOME,否则如下所示,根本定位不到JDK的安装路径 [root@localho ...
- fileupload实现控制大小进行图片上传
if ($(".img-upload").length > 0) { $('.img-upload').fileupload({ type: 'POST', url: &qu ...
- android studio修改项目包名
公司项目都是用eclipse开发的,但是android studio开发已经是大势所趋了,所以在闲暇之余使用了一下androidstudio,这里对androidstudio更改项目包名做一下总结,因 ...
- CSS3之3D效果中的transform运用
css3中添加了很多新的标签 属性 描述 css transform 向元素应用 2D 或 3D 转换. 3 transform-origin 允许你改变被转换元素的位置. 3 transform-s ...
- JDBC连接sql server数据库操作
1.首先,先创建一个连接数据库的工具类: package gu.db.util; import java.sql.Connection; import java.sql.DriverManager; ...
- 手机端rem自适应布局实例
首先要书写核心js代码,控制住页面的初始大小:我是以750px(即iPhone6)的标准,设置font-size:100px:<script> (function (doc, ...