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. 虚拟机centos6.5 --开放端口

    系统:centos6.5 1.查看端口开放情况 /etc/init.d/iptables status 2.开启端口 /sbin/iptables -I INPUT -p tcp --dport -j ...

  2. 大话设计模式C++版——建造者模式

    日常做菜的过程中,经常会有忘记放盐或者放2次盐的经历,最后导致好好的一盘菜让大家无从下口.这个时候就需要用到建造者模式来规范炒菜的过程,来保证每一道菜都会经历加油.放食物.放盐.放味精这4道基本的工序 ...

  3. 中午游泳很海皮-linux&php

    hi 中午又去游泳了,其实本来打算是昨天去的,谁知天公不作美,周一都下雨.今天其实也一样的,有点小雨,不过游得到泳,比什么都好 1.PHP&MySQL -----PHP内置MySQL函数学习( ...

  4. Javascript笔记----实现Page页面右下角置顶按钮.

    从用博客开始,发现博客园中很多博友的博客中在Page右下角都有个图标,不论屏幕怎么拉伸,都始终停留在右下角.点击后页面置顶.后面想想写一个Demo来实现这种效果吧. 一. 图标右下角固定. 1.SS ...

  5. 第10章 同步设备I/O和异步设备I/O(2)_同步IO和异步IO基础

    10.3 执行同步设备I/O (1)对设备读写操作的函数 ①ReadFile/WriteFile函数 参数 描述 hFile 文件句柄 pvBuffer 指向要接收文件数据的缓冲区或把缓冲区数据写入设 ...

  6. Unity 实现物体破碎效果(转)

    感谢网友分享,原文地址(How to Make an Object Shatter Into Smaller Fragments in Unity),中文翻译地址(Unity实现物体破碎效果) In ...

  7. [No00004C]软件工程师的创业陷阱:接私活

    我本身是 Java 工程师出身,写代码至今已超过 15 年,创业也超过 10 年,曾经外包过很多项目给别人,也接过很多外包的项目,现在不接了,只经营电子报发送平台,在二年内累积超过 5000 家企业用 ...

  8. 获取当前时间 和 10s倒计时案例

    1.获取当前的时间,时间没分每秒都在走,(把握现在,将来会是美好的!) <title>获取当前时间</title> <script type="text/jav ...

  9. poj3278 Catch That Cow

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 73973   Accepted: 23308 ...

  10. offsetLeft和style.left的区别

    offsetLeft 获取的是相对于父对象的左边距 left 获取或设置相对于 具有定位属性(position定义为relative)的父对象 的左边距 如果父div的position定义为relat ...