//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. Maven打包web工程成WAR

    其实不一定要通过Goals:package来打war包,直接run as maven bulid也行:

  2. android的m、mm、mmm编译命令

    android的m.mm.mmm编译命令的使用 android源码目录下的build/envsetup.sh文件,描述编译的命令 - m:       Makes from the top of th ...

  3. hdu 5698 瞬间移动(排列组合)

    这题刚看完,想了想,没思路,就题解了 = = 但不得不说,找到这个题解真的很强大,链接:http://blog.csdn.net/qwb492859377/article/details/514781 ...

  4. Error: L6218E: Undefined symbol TIM_ARRPreloadConfig (referred from pwm_output.o).

    出错原因:模板FWLIB中没有添加stm32f10x_tim.c文件.添加即可 一般利用库开发,将ppp.c(ppp.c又调用了库stm32f10x_xx.h)写好之后的调用步骤: 1 将ppp.c和 ...

  5. qt上用opencv显示摄像头视频

    参考:http://blog.csdn.net/augusdi/article/details/8865541 代码如下: 注意,要在ui界面上放置一个“Vertical Layout”控件,调整到合 ...

  6. 项目中用到的logback列子

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <appender ...

  7. Python标准库09 当前进程信息 (os包)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 我们在Linux的概念与体系,多次提及进程的重要性.Python的os包中有查询和 ...

  8. Oracle 查看表空间的大小

    SELECT SUM(bytes) / (1024 * 1024) AS free_space, tablespace_name FROM dba_free_space GROUP BY tables ...

  9. DIV+CSS滑动门效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. IIS6.0中布署MVC站点(转)

    昨晚我写的API上线,API是vs2010 + MVC4开发的,需要布署到windows 2003 server + IIS6.0的环境中,之前一直是布在IIS7.0,比较熟悉, 换到IIS6.0,添 ...