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 ...
随机推荐
- 简析平衡树(一)——替罪羊树 Scapegoat Tree
前言 平衡树在我的心目中,一直都是一个很高深莫测的数据结构.不过,由于最近做的题目的题解中经常出现"平衡树"这三个字,我决定从最简单的替罪羊树开始,好好学习平衡树. 简介 替罪羊树 ...
- 关于explain
> db.imooc_2.find({x:}).explain() { "queryPlanner" : { , "namespace" : " ...
- 制作带复选框的ListView控件
实现效果: 知识运用 ListView控件的GridLines //设置是否在ListView控件中显示网格线 public bool GridLines{get;set} 和CheckBoxes ...
- 2018.5.23 创建用户并授权&&&序列
作业一 视图的创建 1.分页查询2-3范围之间的数据,并用视图(view_student_page)保存. create view view_student_page as select * from ...
- python_67_生成器3
import time def consumer(name): print("%s 准备吃包子啦!"%name) while True: baozi = yield print(& ...
- Vim编辑器基础命令
Linux系统中都默认安装了vi或vim编辑器,两种命令基本一致.vim为Vi IMproved,功能更强大. vim有命令模式,输入模式,和末行模式三种. ➢ 命令模式:控制光标移动,可对文本进行复 ...
- bat 服务启动脚本
当电脑上有多个数据库(特别是Oracle,占用内存大,所以我都是设置为手动启动的,或者想在电脑上运行一下其他UI类软件或玩些游戏的时候也需要暂时关掉,奈何我这渣机(V_V))需要启动或停止的时候,就用 ...
- 十五、MySQL DELETE 语句
MySQL DELETE 语句 你可以使用 SQL 的 DELETE FROM 命令来删除 MySQL 数据表中的记录. 你可以在 mysql> 命令提示符或 PHP 脚本中执行该命令. 语法 ...
- wamp mysql服务意外停止
出现问题: MySQL启动一段时间之后,意外停止.可以再次启动,但是过不了多久又自动停止了. 发现问题: 查看错误日志,发现以下问题: 解决方案: 网上网友分享以下操作: 1.删除data文件夹里面的 ...
- jQuery.each() - jQuery 遍历方法使用介绍
定义和用法 each() 方法规定为每个匹配元素规定运行的函数. 提示:返回 false 可用于及早停止循环. jQuery.each()方法大概有如下几种用法,下面分别进行介绍: 1.选择器.eac ...