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 ...
 
随机推荐
- 洛谷 P1077 摆花
			
题目描述 小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时 ...
 - IIS7.5配置自动添加www 及 限制通过IP访问web
			
IIS7.5配置自动添加www 方法 新建一个站点2(主机名为不带www的站点),将其重定向至带www的URL即可. 注意以下几点 站点2不可与站点1的路径一致,否则会导致站点1也会添加同样的重定向, ...
 - IOS截取部分图片
			
截取部分图片这么简单: - (void)loadView { [[UIApplication sharedApplication] setStatusBarHidden:YES withAni ...
 - IOS  Prefix.pch程序常见文件 的作用
			
#import <Availability.h> #ifndef __IPHONE_5_0 #warning "This project uses features only a ...
 - theano 模块 MLP示例
			
theano 模块 MLP示例,有需要的朋友可以参考下. theano教程Example: MLP: 约定数组为列向量, 层级:将多层传感器定义为一连串的层级,每个层级定义为一个类.类属性包括:权重. ...
 - 通过Jquery获取RadioButtonList选中值
			
推荐 使用第二种,第一种有时候不起作用 第一种:通过find方法 获取RadioButtonList所选中的值 <script type="text/javascript"& ...
 - 基于 muse-ui 封装一个微信公众号上传插件 实现多图上传
			
Vue.component('my-wx-upload', { template: ` <mu-grid-list :cols="3" :cellHeight="9 ...
 - nginx下根据指定路由重定向
			
前言: 最近在搭建vue后台,后端接口是PHP写的,线上构建好之后,需要请求其他域名下的接口,开发环境已经使用proxytable解决了接口问题,为了开发和生成的代码一致, 编译后的代码,放在ngin ...
 - 自定义token,保存到客户端的cookie中,
			
自定义token #原理自定义token,放入cookie中,不用存数据库 #token定义方式 >>>>> "加密字符串"|登陆用户id|用户登陆时 ...
 - Building a Space Station POJ - 2031
			
Building a Space Station POJ - 2031 You are a member of the space station engineering team, and are ...