//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. 案例:用Redis来存储关注关系(php版)

    Redis提供了丰富的数据类型,比起关系型数据库或者简单的Key-Value存储(比如Memcached)来,Redis的数据模型与实际应用的数据模型更相近.比如下面说到的好友关系的存储,原作者使用了 ...

  2. DISPOSE_ON_CLOSE 和 EXIT_ON_CLOSE 的区别

    If you have several JFrames open and you close one that has EXIT_ON_CLOSE it will close all the JFra ...

  3. jplayer中动态添加列表曲目(js提取request中的list数据作为js参数使用)

    jplayer 的播放列表使用如下: $(document).ready(function(){ new jPlayerPlaylist({ jPlayer: "#jquery_jplaye ...

  4. SOA_环境安装系列4_Oracle SOA安装和环境搭建(案例)

    2015-01-02 Created By BaoXinjian

  5. PLSQL_基础系列12_替换函数用法REPLACE / TRANSLATE / REGEXP_REPLACE

    20150806 Created By BaoXinjian

  6. OAF_架构MVC系列2 - Model的概述(概念)

    2014-06-22 Created By BaoXinjian

  7. 关于maven的一些常见用法

    1: 查看插件的目标信息:mvn help:describe 2: 生成javadoc并指定编码:mvn javadoc:javadoc -Dencoding=UTF-8 -Dcharset=UTF- ...

  8. Xcode5创建自己的静态库详解

    首先声明: 本人屌丝一枚,如有不对不妥之处,请大牛指正! 1.静态库工程的建立: Xcode New一个新的project,选择IOS下面的Framework&Library,下面有一个Coc ...

  9. Notepad++隐藏的用法

    Notepad++是一个非常强大的文本编辑器. 它里面有很多有用的插件. 我认为对我比较有帮助的一个是NppExporter.它可以将Notepad++中彩色的代码原样的复制到Word中. 想要获得彩 ...

  10. HtmlparseUtil.java

    该类并不是一个通用的工具类,需要按自己的要求实现,这里只记录了Htmlparse.jar包的一些用法.仅此而已! 详细看这里:http://gundumw100.iteye.com/blog/7043 ...