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. Druid数据库连接池获取连接阻塞(转载)

    一. 背景        17年公司有个项目组在南京做项目的时候,开发框架用的是spring boot ,数据库连接池用的是druid,但老是遇到socket read timeout的错误,不得已放 ...

  2. Tire树(字典树)

    from:https://www.cnblogs.com/justinh/p/7716421.html Trie,又经常叫前缀树,字典树等等.它有很多变种,如后缀树,Radix Tree/Trie,P ...

  3. 吴裕雄--天生自然 JAVA开发学习:数据结构

    import java.util.Vector; import java.util.Enumeration; public class EnumerationTester { public stati ...

  4. MQ消息队列的12点核心原理总结

    1. 消息生产者.消息者.队列 消息生产者Producer:发送消息到消息队列. 消息消费者Consumer:从消息队列接收消息. Broker:概念来自与Apache ActiveMQ,指MQ的服务 ...

  5. Uber坚持不盈利,葫芦里到底卖的是什么药?

    近日,据媒体报道在美国科罗拉多州阿斯彭举办的<财富>科技头脑风暴大会上,Uber CEO达拉·科斯罗萨西表示,Uber无需在2019年下半年上市计划实施前保持盈利状态. 首先要明确一点的是 ...

  6. XMemcached 中文api

    变更历史 2010-06-22 添加客户端分布和SASL验证两节,更新spring配置一节. 2010-06-23 添加maven依赖说明 2010-10-17 1.2.6 released 2011 ...

  7. php 连接oracle插入多张图片的方法

    php连接oracle数据库的时候,其查询.更新.删除数据和MySQL类似,但是增加数据.特别是图片的时候就很不一样,这里面涉及到要创建一个blob对象,用blod对象去保存php图片,下面是当插入多 ...

  8. 关于TensorFlow2的tf.function()和AutoGraph的一些问题解决

    在使用TensorFlow的AutoGraph的时候出现了一些问题,特此记录 AutoGraph did not convert this function. Try decorating it di ...

  9. 吴裕雄--天生自然C语言开发:约瑟夫生者死者小游戏

    个人在一条船上,超载,需要 人下船. 于是人们排成一队,排队的位置即为他们的编号. 报数,从 开始,数到 的人下船. 如此循环,直到船上仅剩 人为止,问都有哪些编号的人下船了呢? #include&l ...

  10. PAT甲级——1065 A+B and C (64bit)

    1065 A+B and C (64bit) Given three integers A, B and C in [−2​63​​,2​63​​], you are supposed to tell ...