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. iNeedle日志下载功能问题

    问题: iNeedle系统本身包含日志下载功能,主要是将web服务器中的用户访问日志按照一定条件进行筛选并下载,提供管理者分析.但是这次的测试中发现iNeedle日志下载一直会卡住,web界面显示正在 ...

  2. C++杂谈(二)初识vector容器与迭代器

    教科书中失踪的vector 很奇怪的一件事情,在当时学习C++的时候,老师并没有讲授容器的内容,当时参考的谭浩强老师的红皮C++也没有这个内容,不知为何.后来再学C++,发现容器是一个很重要的概念,在 ...

  3. 配置安装DVWA

    本文地址:http://www.cnblogs.com/go2bed/p/4162313.html —————————————————— 什么是DVWA? Damn Vulnerable Web Ap ...

  4. 一:c语言(数据类型和运算符)

    #include <stdio.h> /*就是一条预处理命令,它的作用是通知C语言编译系统在对C程序进行正式编译之前需做一些预处理工作.*/ int main() /*C程序就是执行主函数 ...

  5. linux下yum命令出现Loaded plugins: fastestmirror

    yum install的时候提示:Loaded plugins: fastestmirror fastestmirror是yum的一个加速插件,这里是插件提示信息是插件不能用了. 不能用就先别用呗,禁 ...

  6. [转]net中哈希表的使用 Hashtable

    本文转自:http://www.cnblogs.com/gsk99/archive/2011/08/28/2155988.html 以下是PetShop中DBHelper中的使用过程: //创建哈希表 ...

  7. MMORGP大型游戏设计与开发(客户端架构 part1 of vgui)

    作为客户端的重要装饰,UI扮演着极为重要的角色,是客户端中核心的组成.vgui(微GUI)中,提供了核心的接口封装,实现了客户端中常见的界面操作,并结合lua脚本,使得控制界面更加的方便. 构架 总结 ...

  8. SSM三大框架整合详细教程(Spring+SpringMVC+MyBatis)(转)

    使用 SSM ( Spring . SpringMVC 和 Mybatis )已经有三个多月了,项目在技术上已经没有什么难点了,基于现有的技术就可以实现想要的功能,当然肯定有很多可以改进的地方.之前没 ...

  9. 拓扑排序 POJ2367Genealogical tree[topo-sort]

    ---恢复内容开始--- Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4875   A ...

  10. java的构造方法

    当一个类a继承一个类b,类b继承类c,类c继承类d时, 先执行d的构造,然后c.b:当该执行a的构造时,如果有成员变量,就先执行成员变量,最后构造 子类继承父类,子类重写父类的某个方法,当父类构造时, ...