//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. HDU 2717 Catch That Cow(BFS)

    Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...

  2. 在一个窗口中显示多个视频,并在每个子窗口左上角显示系统时间,函数cvShowManyImages是改写的

    #include <cv.h> #include <highgui.h> #include <stdio.h> #include <stdarg.h> ...

  3. dynamic基元类型

    C#编译器允许将一个表达式的类型标记为dynamic.还可以将一个表达式的结果放到一个变量中,并将变量的类型标记为dynamic. 代码使用dynamic表达式/变量来调用一个成员是,编译器会生成特殊 ...

  4. 自己动手写ORM

    http://blog.csdn.net/sundacheng1989/article/category/1350100

  5. UML系列图--用例图

    UML-Unified Model Language 统一建模语言,又称标准建模语言.是用来对软件密集系统进行可视化建模的一种语言. 在UML系统开发中有三个主要的模型: 功能模型: 从用户的角度展示 ...

  6. Java同步块

    原文:http://ifeve.com/synchronized-blocks/ Java 同步块(synchronized block)用来标记方法或者代码块是同步的.Java同步块用来避免竞争.本 ...

  7. XML中五个转义字符

    字符:<,>,&,",© HTML对应的转移字符:< >&"© XML(只有5个)对应的转义字符: < >& " ...

  8. clipse在编写JSP时没有代码提示

    alt /不会出提示按照下面步骤做 1.菜单window- >Preferences- >Java- >Editor- >Content Assist- >Enable ...

  9. 九度OJ1081

    这道题又一次更新了我的世界观与人生观Orz……最开始我是设计了一个O(n)的递推算法,本以为可以轻松AC没想到居然TLE了……然后搜了一下题解,才发现这道题要用矩阵的思想去做. 通过对题目的分析,我们 ...

  10. OpenCV数据结构:CvMat,IplImage,CvArr的应用

    最近看HS算法时,发现在新的OpenCV3.0已经移除了该算法,于是不得不看老版的.这其中涉及到了CvMat,CvArr,IplImage的使用.关于这三个结构与Mat的转换关系,总结如下: (1)派 ...