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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. PHP中的Array

    PHP中的数组是一个有序映射(1对1的关系 key->value).Array是一个综合体:可表示数组.字典.集合等. key可以是int或string.value可以是任意类型. key如下情 ...

  5. codeforces 166C Median - from lanshui_Yang

    C. Median time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  6. Kotlin实现LeetCode算法题之Median of Two Sorted Arrays

    题目Median of Two Sorted Arrays(难度Hard) 方案1,数组合并&排序调用Java方法 import java.util.* class Solution { fu ...

  7. [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 ...

  8. 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 ...

  9. 九章lintcode作业题

    1 - 从strStr谈面试技巧与代码风格 必做题: 13.字符串查找 要求:如题 思路:(自写AC)双重循环,内循环读完则成功 还可以用Rabin,KMP算法等 public int strStr( ...

随机推荐

  1. 搭建持续集成接口测试平台(Jenkins+Ant+Jmeter)

    一.环境准备: 1.JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.Jmeter:http://jme ...

  2. WPF之全局快捷键

    目录 1.WPF快捷键实现方式 2.全局快捷键设置界面 3.Windows API调用 4.注册全局快捷键 5.快捷键触发 WPF快捷键实现方式 WPF快捷键实现主要有自定义快捷键命令和全局快捷键两种 ...

  3. 理解 OpenStack + Ceph (8): 基本的 Ceph 性能测试工具和方法

    本系列文章会深入研究 Ceph 以及 Ceph 和 OpenStack 的集成: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 ...

  4. 查看centos系统版本

    1.查看系统版本 [root@yl-web yl]# cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core) 2.查看内核版本 [ro ...

  5. AC日记——输出亲朋字符串 openjudge 1.7 05

    05:输出亲朋字符串 总时间限制:  1000ms 内存限制:  65536kB 描述 编写程序,求给定字符串s的亲朋字符串s1. 亲朋字符串s1定义如下:给定字符串s的第一个字符的ASCII值加第二 ...

  6. Qt 静态编译后的exe太大, 可以这样压缩.

    1. 下载PECompact 下载地址:http://download.csdn.net/download/sniper_bing/7669247 ,  不行大家就去baidu搜索下载就可以了这个是绿 ...

  7. Android4.0-Fragment框架实现方式剖析(一)

    1.什么是Fragment? Fragment包含在Activity中,Fragment只能存在于Activity的上下文(context)内,没有Activity就无 法使用Fragment,因此F ...

  8. linux svn

    1.回滚 一直在找svn回滚的方法,这个还是很实用的,屡试不爽阿 经常由于坑爹的需求,功能要切回到之前的某一个版本.有两种方法可以实现: 方法1: 用svn merge  1) 先 svn up,保证 ...

  9. Java集合系列:-----------02Collection架构

    出处:http://www.cnblogs.com/skywang12345/p/3308513.html 我们知道Collection是和Map架构平级的,我们看一下这个架构是怎样的. 他主要的两个 ...

  10. 微软职位内部推荐-Service Engineer II for Azure Cloud Network

    微软近期Open的职位: Are you interested in helping to drive the direction of a product that defines the clou ...