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. HTTP协议小结

    HTTP/0.9已过时.只接受GET一种请求方法,没有在通讯中指定版本号,且不支持请求头.由于该版本不支持POST方法,因此客户端无法向服务器传递太多信息. HTTP/1.0 这是第一个在通讯中指定版 ...

  2. [转]ASP.NET MVC Dynamic Themes

    本文转自:http://www.codeproject.com/Articles/32847/ASP-NET-MVC-Dynamic-Themes Download source code - 148 ...

  3. Servlet分页技术

    这是看韩顺平老师的servlet视频,自己动手写的,楼主看韩顺平老师的servlet是2006制作的,用的是sql server数据库,自己又用的是oracle数据库,所以怕有的同学遇到同样的问题,不 ...

  4. POJ2184 Cow Exhibition[DP 状态负值]

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12420   Accepted: 4964 D ...

  5. sql索引的填充因子多少最好,填充因子的作用?

    当创建一个新索引,或重建一个存在的索引时,你可以指定一个填充因子,它是在索引创建时索引里的数据页被填充的数量.填充因子设置为100意味着每个索引页100%填满,50%意味着每个索引页50%填满. 如果 ...

  6. 这几天在搞UNITY3D,感觉回到了AS2

    这几天在搞UNITY3D,感觉回到了AS2 代码没有MAIN, 代码在屏幕上,和元件绑定

  7. codevs[1300]文件排版

    Description 写电子邮件是有趣的,但不幸的是经常写不好看,主要是因为所有的行不一样长,你的上司想要发排版精美的电子邮件,你的任务是为他编写一个电子邮件排版程序. 完成这个任务最简单的办法是在 ...

  8. ubuntu下解析udt数据包

    udt是通过udp进行端到端可靠传输的一个协议,有其默认拥塞控制算法. 之前ubuntu下wireshark的版本是1.10,不能直接解析udt数据包[1],升级到最新的2.0.0即可过滤udt数据包 ...

  9. javascript的几个小技巧

    1.在循环中缓存array.length 这个技巧很简单,这个在处理一个很大的数组循环时,对性能影响将是非常大的.基本上,大家都会写一个这样的同步迭代的数组. for(var i=0;i<arr ...

  10. 如果觉得配置文件没有错,但web-dev-server总是报错,可以在hosts文件里加一行127.0.0.1 localhost

    如果觉得配置文件没有错,但web-dev-server总是报错,可以在hosts文件里加一行127.0.0.1 localhost