Gold Nuggets Distribution(0490)

Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 421 Accepted: 234
 
Description
Bosses have a bag of gold. Each month there will be two employees to their outstanding performance were a gold award. In line with the rituals, ranking first employees will receive the heaviest nugget, ranked second employee will be the lightest gold. Under this method, unless the Nuggets to a new bag, otherwise employees received the first gold always be employees than the second-Nuggets. If there is a new cyclical Nuggets joined bag, every month to find the lightest and most of the Nuggets. Assuming that there is a comparison of weight machines, we hope that at least by comparison to identify the number and the lightest weight of gold.
(题目描述就不翻译了,简而言之的意思就是,找出数组中的最大元素和最小元素,有个要求就是,比较的次数最少)
 
Input
two lines 
the first line is a number of gold nuggets and less than 50000 
the second line are weight of every gold nugget.
 
Output
two numbers 
the first is weight of the heaviest nugget 
the second is weight of the lightest gold
 
Sample Input
6
5 2 7 6 3 4
 
Sample Output
7 2
 
 Hint
Source
MrYang
 
 #include<iostream>
using namespace std; int a[]; int main()
{
int n,i,j,max=,min=;
cin>>n;
for(i=;i<n;i++)
cin>>a[i];
for(i=,j=n-;i<=j;i++,j--)
{
if(a[i]<a[j])
{
if(a[i]<min)
min=a[i];
if(a[j]>max)
max=a[j];
}
else
{
if(a[j]<min)
min=a[j];
if(a[i]>max)
max=a[i];
}
}
cout<<max<<' '<<min<<endl;
return ;
}

注:两个数比较,则那个大的数,不可能成为这组数中最小的数,同理,那个小的数,不可能成为这组数中最大的数。从常用的 2*n 次比较,变成了(n/2)*3=1.5*n 次比较。

SWUST OJ Gold Nuggets Distribution(0490)的更多相关文章

  1. [Swust OJ 404]--最小代价树(动态规划)

    题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535   Des ...

  2. [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)

    题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...

  3. SWUST OJ NBA Finals(0649)

    NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128   Descri ...

  4. [Swust OJ 1023]--Escape(带点其他状态的BFS)

    解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535     Descript ...

  5. [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)

    题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535   Descriptio ...

  6. [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)

    题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...

  7. [Swust OJ 1026]--Egg pain's hzf

      题目链接:http://acm.swust.edu.cn/problem/1026/     Time limit(ms): 3000 Memory limit(kb): 65535   hzf ...

  8. [Swust OJ 1139]--Coin-row problem

    题目链接:  http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...

  9. [Swust OJ 385]--自动写诗

    题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535    Descripti ...

随机推荐

  1. JS—Function类型

    1.函数的声明方式有三种普通函数的声明方式function box(num1,num2){ return num1+num2;}alert(box(1,2)); 使用变量初始化函数var box = ...

  2. if_while

    import random secret=random.randint(1,10) tmp=input("请输入一个数") guess=int(tmp) while guess!= ...

  3. 将iso mount 到nfs 目录问题

    最近有个需求,需要在多台系统安装程序,安装文件是iso 格式的,最普通的办法就是拷贝到其它系统,然后mount loop 到本地目录. 但是比较麻烦,而且当前已经有一个nfs 服务端了,于是想出一个办 ...

  4. Data总结

    getTime() 方法可返回距 1970 年 1 月 1 日之间的毫秒数 var d = new Date(); var n = d.getTime(); //一长串数字

  5. 关于Weblogic的知识点

    一.解决Weblogic域创建.启动.进入控制台慢问题 搭建Weblogic 11g和12c环境时发现,安装正常,以默认组件安装,但是创建域的时候特别慢,一般需要几分钟至10分钟,卡在“创建域安全信息 ...

  6. Matlab高级教程_第四篇:Matlab高级函数_关键词:arrayfun

    % 定义一个句柄并用这个句柄求值 h = @sin; h(3) % % 命令窗口返回内容 % h(3) % ans = % 0.1411 %定义一个完整句柄,@参数+表达式的形式,并给句柄传参 h1 ...

  7. Django_前介

    Django 1.软件框架 ​ 一个公司是由公司中的各部部门来组成的,每一个部门拥有特定的职能,部门与部门之间通过相互的配合来完成让公司运转起来. ​ 一个软件框架是由其中各个软件模块组成的,每一个模 ...

  8. linux中ftp中文名乱码问题

    问题触发环境 1. java中使用org.apache.commons.net.ftp.FTPClient包 2. 通过chrome浏览器的file标签上传文件 3. 在windows上部署的File ...

  9. 01 语言基础+高级:1-7 异常与多线程_day05 【异常、线程】

    day05 [异常.线程] 主要内容 异常.线程 教学目标 能够辨别程序中异常和错误的区别 说出异常的分类 说出虚拟机处理异常的方式 列举出常见的三个运行期异常 能够使用try...catch关键字处 ...

  10. More 'long-life' plastic bags being used

    1 1.1 roll out v. 推广,或实行 1.2 pilot v. 试行 n. 飞行员 1.3 bags for life 可重复使用的环保购物袋 2 2.1 How many times a ...