HDU5857 Median 模拟
Median
InputFirst line contains a integer T, means the number of test cases. Each case begin with two integers n, m, means the length of the sequence and the number of queries. Each query contains two lines, first two integers l1, r1, next line two integers l2, r2, l1<=r1 and l2<=r2.
T is about 200.
For 90% of the data, n, m <= 100
For 10% of the data, n, m <= 100000
A[i] fits signed 32-bits int.
OutputFor each query, output one line, the median of the query sequence, the answer should be accurate to one decimal point.Sample Input
1
4 2
1 2 3 4
1 2
2 4
1 1
2 2
Sample Output
2.0
1.5
给你一个有序序列,让你再两个区间内找到构造成新序列的其中位数
这个题,我们可以把它转换为两个平衡的区间,即确保第一个l和r都比第二个的小
然后就有是否相交,相交了在左边,在中间,在右边
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int l1,r1,l2,r2;
int a[N];
int la(int s)
{
if(r1<=l2)
{
if(r1-l1+>=s)return a[l1+s-];
s-=r1-l1+;
return a[l2+s-];
}
if(l2-l1>=s)return a[l1+s-];
if(l2-l1>=s-(r1-l2+)*)
{
s-=l2-l1+;
return a[l2+s/];
}
s-=r1-l1+;
return a[l2+s-]; }
int main()
{
ios::sync_with_stdio(false),cin.tie(),cout.tie();
int T;
cin>>T;
while(T--)
{
int n,q;
cin>>n>>q;
for(int i=; i<=n; i++)cin>>a[i];
for(int i=; i<q; i++)
{
cin>>l1>>r1>>l2>>r2;
if(l2<l1)swap(l1,l2);
if(r2<r1)swap(r1,r2);
int cd=r2+r1-l1-l2+;
if(cd&)
{
printf("%.1f\n",1.0*la(cd/+));
}
else
{
printf("%.1f\n",0.5*la(cd/+)+0.5*la(cd/));
}
}
}
return ;
}
HDU5857 Median 模拟的更多相关文章
- hdu5857 Median(模拟)
Median Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hdu-5857 Median(水题)
题目链接: Median Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- POJ 3784 Running Median (模拟水过带翻译)
Description Moscow is hosting a major international conference, which is attended by n scientists fr ...
- Codeforces Round #577 (Div. 2) C. Maximum Median (模拟,中位数)
题意:给你一个长度为奇数\(n\)的序列.你可以对任意元素加上\(k\)次\(1\),求操作后的中位数最大. 题解:先对序列进行排序,然后对中位数相加,如果中位数和后面的元素相等,就对后面所有和当前中 ...
- Codeforces Round #550 (Div. 3) E. Median String (模拟)
Median String time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 【HDU5857】Median
题意 给出一个长度为n的有序序列.给出m个询问,每个询问包括四个正整数l1,r1,l2,r2你用l1tor1的和l2tor2的元素来组成一个新的序列,然后找出这个序列的中位数. 分析 这是当时Spri ...
- median(NOIP模拟赛Round 3)
也是神奇的题目.. 原题传送门 首先看到这道题目,很明显我们需要线性算法 1.前缀和+统计 2.DP+统计 对于第一种算法,我们可以对于任何一个a[i]对b进行比较,如果大于b标上1,等于b标上0,小 ...
- 10.7 csp-s模拟测试63 Median+Game+Park
我堕落了 我觉得任牛逼的问题也是我的问题 T1 Median T2 Game T3 Park
- [CSP-S模拟测试]:Median(暴力+模拟)
题目描述 定义两个数列: $$S=\{S(1),S(2),...,S(n)\}\text{和}S_2\{S_2(1),S_2(2),...,S_2(n)\}$$ $$S(k)=(p_k\times k ...
随机推荐
- spa 小程序的研发随笔 (2) --- 预编译
因为是连续写的2篇随笔,废话不多说.直接进入正题. 选择预编译的工具时,笔者采用了gulp.虽然,如今市面上大多采用的多为webpack,使用gulp也是有自己的缘由的. webpack的最主要特点是 ...
- co-dialog弹出框组件-版本v2.0.0
co-dialog theme 访问git:co-dialog 版本v2.0.0 主题2 coog.app('.theme2').use({ title: 'JUST CHECKING.', mess ...
- World Wind Java开发之九——阶段小结(转)
http://blog.csdn.net/giser_whu/article/details/42785875 将近一个月没有更新了,一是因为项目的事情,二是期末考试复习,三是玩啦.上一篇博客搭建起了 ...
- hdu-1233 还是畅通工程---MST模板
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1233 题目大意: 求MST最小生成树 解题思路: Prim算法直接套即可 #include<b ...
- pandas 代码
def get_train_data(): df = pd.read_csv('data/train.csv', encoding='utf_8') # df1 = pd.read_csv('data ...
- CUDA:Supercomputing for the Masses (用于大量数据的超级计算)-第四节
了解和使用共享内存(1) Rob Farber 是西北太平洋国家实验室(Pacific Northwest National Laboratory)的高级科研人员.他在多个国家级的实验室进行大型并行运 ...
- 函数定义和调用 -------JavaScript
本文摘要:http://www.liaoxuefeng.com/ 定义函数 在JavaScript中,定义函数的方式如下: function abs(x) { if (x >= 0) { ret ...
- IBM MQ Explore使用
一,版本说明: 系统:win10.MQ:V9.04 二.关于帮助文档: 1.读了差不多一大半,个人感觉说明的比较生僻,应该是直译过来的.但是还是可以从这里面学一下基本的操作. 2.对于一些基本的操作, ...
- 已解决: idea创建并部署SpringMVC项目时 报错 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
用IDEA创建并运行SpringMVC项目时,最初发现没有Servlet包,这个问题已在上篇解决,然而当我们尝试去运行此时的SpringMVC项目时,发现仍然有错误.ClassNotFoundExce ...
- centos下 将(jgp、png)图片转换成webp格式
由于项目要求需要将jpg.png类型的图片 转换成webp格式,最开始使用了php gd类库里 imagewebp 方法实现,结果发现转换成的webp格式文件会偶尔出现空白内容的情况.像创建了一个透 ...