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. Bootstrap模态框(modal)垂直居中

    http://v3.bootcss.com/ 自己也试了改了几种方式也不容乐观,发现在窗口弹出之前是获取不到$(this).height()的值,本想着是用($(window).height()-$( ...

  2. 工作中常用的Linux命令:crontab命令

    本文链接:http://www.cnblogs.com/MartinChentf/p/6060252.html (转载请注明出处) crontab是一个用来设置.删除或显示供守护进程cron执行的定时 ...

  3. label与input间距的小问题

    先码后文 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3 ...

  4. css中单位em和rem

    一.介绍 1.em w3cschool中给出css中尺寸单位如下: 单位 描述 % 百分比 in 英寸 cm 厘米 mm 毫米 em 1em 等于当前的字体尺寸. 2em 等于当前字体尺寸的两倍. 例 ...

  5. git错误:Target branch can't be blank

    一.问题描述 遇到一个问题:Target branch can't be blank 因为问题再没有重现,所以拿一张网上的图: 情况是,比如a是项目的owner,有一个项目a/Project. b从a ...

  6. 睡觉问题早晚成为我顶头疼的问题。。。-PHP

    hi 昨晚又作自己,睡不好整个人都不好... 1.PHP实现页面静态化 二.纯静态化 2.2 实现页面纯静态化的原理 --基本方式 file_put_contents()函数: 使用php内置缓存机制 ...

  7. sql中视图的作用

    视图是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的查询所引用的表,并且在引用视图时动态 ...

  8. UVALive 5066 Fire Drill --BFS+DP

    题意:有一个三维的地图,有n个人被困住,现在消防队员只能从1楼的一个入口进入,营救被困者,每一个被困者有一个价值,当消防队员找到一个被困者之后,他可以营救或者见死不救,如果救的话,他必须马上将其背到入 ...

  9. [Flash 3D] 又是一个难题解决了。(Flash3D在android中运行)

    做了一些away3D(4.1.6)+Flash cc,项目比较大,面数多达2000万个,发现电脑还有跑20多帧,可见away3d表现确实相当不错.想把这些东西放到手机上来看,却发现总是白屏,网上搜索了 ...

  10. string、math类、random随机数、datetime、异常保护

    今天讲的知识点比较多,比较杂,以至于现在脑子里还有点乱,慢慢来吧... string (1)string.length; (获得你string字符串的长度) (2)a = a.Trim(); 重新赋值 ...