http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/A

In an open credit system, the students can choose any course they like, but there is a problem. Some of the students are more senior than other students. The professor of such a course has found quite a number of such students who came from senior classes (as if they came to attend the pre requisite course after passing an advanced course). But he wants to do justice to the new students. So, he is going to take a placement test (basically an IQ test) to assess the level of difference among the students. He wants to know the maximum amount of score that a senior student gets more than any junior student. For example, if a senior student gets 80 and a junior student gets 70, then this amount is 10. Be careful that we don’t want the absolute value. Help the professor to figure out a solution. Input Input consists of a number of test cases T (less than 20). Each case starts with an integer n which is the number of students in the course. This value can be as large as 100,000 and as low as 2. Next n lines contain n integers where the i’th integer is the score of the i’th student. All these integers have absolute values less than 150000. If i < j, then i’th student is senior to the j’th student. Output For each test case, output the desired number in a new line. Follow the format shown in sample input-output section. Sample Input 3 2 100 20 4 4 3 2 1 4 1 2 3 4 Sample Output 80 3 -1

题意:给出一串数字,先出现的与后出现的数的最大差值是多少,有t组(少于20)数据,每组最多100,000个数,这些数绝对值小于150000。

题解:每组的n个数,读入的第一个数作为maxn,表示当前出现的最大数,接下来每读一个数,看看用maxn(前面最大的数)减去a(当前数)是否比ans(之前的计算的最大差值)更大,ans=max(ans,maxn-a),然后比较a是否比maxn大,maxn=max(maxn,a)

代码:

  1. #include<cstdio>
  2. #include<algorithm>
  3.  
  4. #define mm=100005;
  5.  
  6. using namespace std;
  7.  
  8. int t,n,a,ans,maxn;
  9. int main(){
  10. scanf("%d",&t);
  11. while(t--){
  12. ans=-;
  13. scanf("%d",&n);
  14. scanf("%d",&maxn);
  15. for(int i=;i<n;i++)
  16. {
  17. scanf("%d",&a);
  18. ans=max(maxn-a,ans);
  19. maxn=max(a,maxn);
  20. }
  21. printf("%d\n",ans);
  22. }
  23. }

  

【UVA 11078】BUPT 2015 newbie practice #2 div2-A -Open Credit System的更多相关文章

  1. 【UVA 401】BUPT 2015 newbie practice #2 div2-B-Palindromes

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/B A regular palindrome is a str ...

  2. 【CodeForces 312B】BUPT 2015 newbie practice #3A Archer

    题 SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the targ ...

  3. 【CodeForces 605A】BUPT 2015 newbie practice #2 div2-E - Sorting Railway Cars

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/E Description An infinitely lon ...

  4. 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D The famous Korean internet co ...

  5. 【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/C Description I’ve bought an or ...

  6. 【巧妙算法系列】【Uva 11464】 - Even Parity 偶数矩阵

    偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...

  7. 【贪心+中位数】【UVa 11300】 分金币

    (解方程建模+中位数求最短累积位移) 分金币(Spreading the Wealth, UVa 11300) 圆桌旁坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一 ...

  8. 【UVa 10881】Piotr's Ants

    Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...

  9. 【UVa 116】Unidirectional TSP

    [Link]:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

随机推荐

  1. codeforces 487B B. Strip(RMQ+二分+dp)

    题目链接: B. Strip time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. C# Process执行bat

    Process类 System.Diagnostics 命名空间提供类,使您能够与系统进程.事件日志和性能计数器进行交互. Process类提供对本地和远程进程的访问并使您能够启动和停止本地系统进程. ...

  3. 反序列化存入数据库里面的session数据

    session数据存取的方法可通过session.serialize_handler方法来判断,反序列化可通过下面的unserialize方法,参考http://stackoverflow.com/q ...

  4. 对访问修饰关键字public, protected, internal and private的说明

    对访问修饰关键字public, protected, internal and private的说明1.msdn: Internal types or members are accessible o ...

  5. String类常用方法。

    一,字符数组与字符串. 一个字符串可以变成一个字符数组,同样,一个字符数组可以变成一个字符串. 在String类中提供了以下操作方法. 1)将字符串变成字符数组:public char[] toCha ...

  6. 1976 Queen数列

    1976 Queen数列  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 将1到N的整数数列(1 ...

  7. Linux 下安装 jdk步骤:

    一:在安装自己下载的jdk之前,要先看看新安装的CentOS 6.4系统自带的jdk版本,如果存在最好是卸载掉,然后再安装自己下载的jdk版本,如何卸载linux系统自带的jdk网上有很多例子,相信大 ...

  8. C语言 二级指针内存模型③

    //二级指针内存模型③ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #incl ...

  9. Oracle数据库,数字强制显示2位小数(转)

    Oracle数据库,数字强制显示2位小数 在银行.财务等对数字要求敏感的系统中,数字的显示一般有着严格的要求.今遇到一个需求,如题,要求将数字以两位小数的格式显示,如果没有小数,则强制显示为0.例如: ...

  10. 在64位windows下使用instsrv.exe和srvany.exe创建windows服务

    在64位windows下使用instsrv.exe和srvany.exe创建windows服务   在32位的windows下,包括windows7,windows xp以及windows 2003, ...