//the first k elements interviewed and rejected,

//for  the latter n-k elements ,if value >max,return value,  else return n'elements.

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define ARRAY_SIZE 1000
#define RANDOM_SIZE 100
int buf [ARRAY_SIZE];
int main()
{
srand((unsigned int )time(0));
int i,n;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)buf[i]=rand()%RANDOM_SIZE;
for(i=1;i<=n;i++)printf("%d ",buf[i]);
printf("*\n");
//creat random value of buffer and print
//online maximum
int k=n/2,max=-RANDOM_SIZE;
for(i=1;i<=k;i++)
{
if(max<buf[i])max=buf[i];
}
for(i=k+1;i<=n;i++)
{
if(buf[i]>=max)
{
printf("%d\n",buf[i]);
exit(0);
}
}
printf("%d\n",buf[n]);
}
}

CLRS: online maximum (n,k)algorithm的更多相关文章

  1. [Algorithm] Maximum Contiguous Subarray algorithm implementation using TypeScript / JavaScript

    Naive solution for this problem would be caluclate all the possible combinations: const numbers = [1 ...

  2. 1420. Build Array Where You Can Find The Maximum Exactly K Comparisons

    Given three integers n, m and k. Consider the following algorithm to find the maximum element of an ...

  3. [转载]Maximum Flow: Augmenting Path Algorithms Comparison

    https://www.topcoder.com/community/data-science/data-science-tutorials/maximum-flow-augmenting-path- ...

  4. [UCSD白板题] Pairwise Distinct Summands

    Problem Introduction This is an example of a problem where a subproblem of the corresponding greedy ...

  5. 【UVA 1380】 A Scheduling Problem (树形DP)

    A Scheduling Problem   Description There is a set of jobs, say x1, x2,..., xn <tex2html_verbatim_ ...

  6. 一位学长的ACM总结(感触颇深)

    发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...

  7. Naive Bayes Theorem and Application - Theorem

    Naive Bayes Theorm And Application - Theorem Naive Bayes model: 1. Naive Bayes model 2. model: discr ...

  8. 关于并行计算的Scan操作

    simple and common parallel algorithm building block is the all-prefix-sums operation. In this chapte ...

  9. HUST 1352 Repetitions of Substrings(字符串)

    Repetitions of Substrings Description The “repetitions” of a string S(whose length is n) is a maximu ...

随机推荐

  1. ExtJs4 SpringMvc3 实现Grid 分页

    新建一个Maven webapp项目,webxml以及spring配置没什么需要注意的,不再赘述. Maven依赖:(个人习惯,有用没用的都加上...) <project xmlns=" ...

  2. Hadoop使用lzo压缩格式

    在hadoop中搭建lzo环境: wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.06.tar.gz export CFLAGS ...

  3. BIP_开发案例06_以RB.RDF为数据源BIP.RTF为模板的简单例子(案例)

    2014-05-31 Created By BaoXinjian

  4. GL_GL系列 - 日记账处理管理分析(案例)

    2014-07-07 Created By BaoXinjian

  5. PO_PO系列 - 收货管理分析(案例)

    2014-07-01 Created By BaoXinjian

  6. rand()随机数的产生

    #include "stdio.h"#include<stdlib.h>用下列公式即可得到指定范围[m,n]的随机数: r = rand()%(n - m + 1) + ...

  7. php 快速fork出指定个子进程

    $pids = array(); $child_pid = pcntl_fork(); if ($child_pid == -1) { throw new Exception( __METHOD__ ...

  8. YCbCr;YUV;RGB

    1.  来源的差异 yuv色彩模 型来源于rgb模型,该模型的特点是将亮度和色度分离开,从而适合于图像处理领域. 应用:basic color model used in analogue color ...

  9. SQL Server 2005中的分区表(六):将已分区表转换成普通表(转)

    我的俄罗斯名叫作“不折腾不舒服斯基”,所以,不将分区表好好折腾一下,我就是不舒服. 在前面,我们介绍过怎么样直接创建一个分区表,也介绍过怎么将一个普通表转换成一个分区表.那么,这两种方式创建的表有什么 ...

  10. eclipse快速收缩展开代码

    快速折叠所有代码和展开所有代码都是CTRL+SHIFT+/