The median of multi ascending array
Given 17 arrays,every array is ascending.The task is to get the median of all these numbers.
0 1 2 3 4 this is an array with 5 elements,the median is (5/2).
0 1 2 3 4 5 this is an array with 6 elements,the median is (6/2).
If we index an the elements from 0,the median is the element's count/2.
Input format
sort them:
36 elements(from a[0] to a[35]).The median is the a[18](the 19th)= 54.
The method above is O(n).
The method below is O(lgn).The keythought in the below method is alike with trisection.
#include<iostream>
#include<math.h>
using namespace std;
][];
];
int n;
int main(){
;
cin>>n;
;i<n;i++){
cin>>len[i];
l+=len[i];
;j<len[i];j++)cin>>a[i][j];
}
);
/*
If forward l-(l/2) steps,the minimum value is the ans.
*/
int ans;
while(rem){
int s=ceil(1.0*rem/n);
;
;
//At least,there is someone forward ceil(rem/n) steps.who should do this?
;i<n;i++){
if(len[i]){
,len[i]-s);
if(a[i][j]>mi){
mi=a[i][j];
ii=i;
}
}
}
,len[ii]-s);
rem-=(len[ii]-j);
len[ii]=j;
ans=min(ans,a[ii][j]);//I made a mistake here,should use 'min' to update ans.
}
cout<<ans<<endl;
;
}
The median of multi ascending array的更多相关文章
- ZOJ2481 Unique Ascending Array 2017-04-18 23:08 33人阅读 评论(0) 收藏
Unique Ascending Array Time Limit: 2 Seconds Memory Limit: 65536 KB Given an array of integers ...
- Median of Two Sorted Array leetcode java
题目: There are two sorted arrays A and B of size m and n respectively. Find the median of the two sor ...
- LeetCode 4 Median of Two Sorted Array
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted ...
- PHP中的Array
PHP中的数组是一个有序映射(1对1的关系 key->value).Array是一个综合体:可表示数组.字典.集合等. key可以是int或string.value可以是任意类型. key如下情 ...
- codeforces 166C Median - from lanshui_Yang
C. Median time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Kotlin实现LeetCode算法题之Median of Two Sorted Arrays
题目Median of Two Sorted Arrays(难度Hard) 方案1,数组合并&排序调用Java方法 import java.util.* class Solution { fu ...
- [leetcode]4. Median of Two Sorted Arrays俩有序数组的中位数
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- 215. Kth Largest Element in an Array(QuickSort)
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...
- 九章lintcode作业题
1 - 从strStr谈面试技巧与代码风格 必做题: 13.字符串查找 要求:如题 思路:(自写AC)双重循环,内循环读完则成功 还可以用Rabin,KMP算法等 public int strStr( ...
随机推荐
- 实例浅析epoll的水平触发和边缘触发,以及边缘触发为什么要使用非阻塞IO
一.基本概念 我们通俗一点讲: Level_triggered(水平触发):当被监控的 ...
- 完整卸载 kubuntu-desktop from Ubuntu 14.04 LTS
系统 ubuntu 14.04 LTS 64Bit 目的:卸载kubuntu-desktop 方法一: sudo apt-get remove libkde3support4 k3b-data ntr ...
- 准备使用 Office 365 中国版--邮箱迁移
微软产品一贯的作风是从来不缺文档和教程,Office 365也不例外.无论是最终用户还是企业IT管理员,都可参照Office 365使用指南顺利的开启Office 365之旅.不过比较奇怪的是,貌似很 ...
- html5语法
html5语法沿用html语法,但更简单,更人性化. 一.DOCTYPE及字符编码 DOCTYPE:<!doctype html>或者<!DOCTYPE html>因为html ...
- POJ3255Roadblocks[次短路]
Roadblocks Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 12697 Accepted: 4491 Descr ...
- 为什么那么多人想开发一元夺宝类app?
别拿你的无知和愚蠢,来证明主观的判断! 国人对一切事物具有怀疑的本性是好的, 但是若不建立于科学的分析方法, 那就是愚昧! 身边有朋友玩夺宝投入较多,产出较少,于是向我求助.想从数据分析的角度知道到底 ...
- 直接拿来用!最火的Android开源项目(完结篇)
直接拿来用!最火的Android开源项目(完结篇) 2014-01-06 19:59 4785人阅读 评论(1) 收藏 举报 分类: android 高手进阶教程(100) 摘要:截至目前,在GitH ...
- SOAP-XML请求(iOS应用下集成携程api)
用携程机票为例: 携程联盟 飞机票.门票 联盟ID:278639 站点ID:739462 密钥KEY:BE57B925-E8CE-4AA2-AC8E-3EE4BBBB686F API_URL:open ...
- CF#345 (Div1)
论蒟蒻如何被cf虐 以下是身败名裂后的题解菌=========== Div1 A.Watchmen 有n个点,每个点有一个坐标.求曼哈顿距离=欧几里得距离的点对数量. 只需要统计x或y一样的点对数量. ...
- fabric批量操作远程操作主机的练习
fabric是python的一个基于命令行的自动化部署框架,用docker开了两个容器来学习fabric. #!/usr/bin/env python #-*- coding=utf-8 -*- fr ...