CLRS: online maximum (n,k)algorithm
//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的更多相关文章
- [Algorithm] Maximum Contiguous Subarray algorithm implementation using TypeScript / JavaScript
Naive solution for this problem would be caluclate all the possible combinations: const numbers = [1 ...
- 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 ...
- [转载]Maximum Flow: Augmenting Path Algorithms Comparison
https://www.topcoder.com/community/data-science/data-science-tutorials/maximum-flow-augmenting-path- ...
- [UCSD白板题] Pairwise Distinct Summands
Problem Introduction This is an example of a problem where a subproblem of the corresponding greedy ...
- 【UVA 1380】 A Scheduling Problem (树形DP)
A Scheduling Problem Description There is a set of jobs, say x1, x2,..., xn <tex2html_verbatim_ ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
- Naive Bayes Theorem and Application - Theorem
Naive Bayes Theorm And Application - Theorem Naive Bayes model: 1. Naive Bayes model 2. model: discr ...
- 关于并行计算的Scan操作
simple and common parallel algorithm building block is the all-prefix-sums operation. In this chapte ...
- HUST 1352 Repetitions of Substrings(字符串)
Repetitions of Substrings Description The “repetitions” of a string S(whose length is n) is a maximu ...
随机推荐
- Maven错误在这里看【项目无法成功编译由于maven未成功下载依赖导致】
- dede的幻灯片除了首页其他页面也显示的方法,
<script language='javascript'> linkarr = new Array(); picarr = new Array(); textarr = new Arra ...
- Expert C# 5.0中的Linq部分
1.先看看.NET中的Linq 2.扩展方法 3.Lambda表达式和表达式树 4.Linq中的延迟操作 5.Linq中的查询方法 5.1分割操作 5.2连接操作 5.3排序操作 5.4分组和连接 5 ...
- uboot 的内存命令使用 mw (修改) md (显示)
修改:mw [内存地址] [值] [长度] 例如:mw 0x02000000 0 128 表示修改地址为0x02000000~0x02000000+128的内存值为0. 显示:md [内存地址] [长 ...
- ylbtech-dbs:ylbtech-1,FAM(家庭资产管理系统)
ylbtech-dbs:ylbtech-1,FAM(家庭资产管理系统) -- =============================================-- Family Assets ...
- Java拾穗
1.Class.forName("com.wzh.test.loadClass"); Class.forName("com.mysql.jdbc.Driver" ...
- Centos安装(更新)git(亲测有效)
Centos 6.5默认安装的是git 1.7.X 版本,使用过程中会有一些奇怪的问题,对于用户名.密码支持不是很友好.将Centos6.5上的git更新到2.0.5,方法如下: 1.安装编译git时 ...
- [SQL]合并字符串
--带符号合并行列转换 --有表t,其数据如下: /* a b 1 1 1 2 1 3 2 1 2 2 3 1 --如何转换成如下结果: a b 1 1,2,3 2 1,2 3 1 */ drop t ...
- Error Dropping Database (Can't rmdir '.test\', errno: 17)
MySql 删除数据库出错:Can't rmdir '.\test\', errno: 17 到test数据下的所在的目前data\test目录,删除掉所有的文件后,就可以删除数据了
- flash 读取系统默认编码
java有类可以直接读取,但貌似flash没有. Charset.defaultCharset(); 但是浏览器里可以有. document.defaultCharset;//从当前的区域语言中获取默 ...