11078 - Open Credit System

Time limit: 3.000 seconds

Problem E
Open Credit System
Input: Standard Input

Output: Standard Output

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                             Output
for Sample Input

3

2

100

20

4

4

3

2

1

4

1

2

3

4

 

80
3
-1

题意:给一个长度为n的整数序列a0,a1,a2,,,,,,an-1,找出两个整数ai和aj(i<j)使得ai-aj最大。。。

思路:如果直接二重循环是不可取的,因为时间复杂度O(n^2)在n=100000下会超时,所以我们可以选择小于j的最大ai,每次记录ans,最后的ans就是结果,优化后可以是、使时间和空间复杂度都变成O(n);

ps:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2019

#include<cstdio>
#include<algorithm>
using namespace std;
int num[];
int maxnum,ans; int main()
{
int T,N,i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&N);
scanf("%d%d",&num[],&num[]);
maxnum=num[]>num[]?num[]:num[];
ans=num[]-num[];
for(i=;i<N;i++)
{
scanf("%d",&num[i]);
ans=max(ans,maxnum-num[i]);
maxnum=max(maxnum,num[i]);
}
printf("%d\n",ans);
}
return ;
}

Open Credit System(UVA11078)的更多相关文章

  1. 关于system(”pause“);的作用和意义

    注意:不要再return 的语句之后加,那样就执行不到了. system() 是调用系统命令:pause 暂停命令: 如果加有  system(”pause“): 这样在运行到此处时,会显示“Pres ...

  2. uva11078 - Open Credit System(动态维护关键值)

    这道题使用暴力解法O(n*n)会超时,那么用动态维护最大值可以优化到O(n).这种思想非常实用. #include<iostream> #include<cstdio> #in ...

  3. UVA 11078 Open Credit System(扫描 维护最大值)

    Open Credit System In an open credit system, the students can choose any course they like, but there ...

  4. cocos2d-x:Particle System(粒子系统)

    一.粒子系统简介: 粒子系统最早出现在80年代,主要用于解决由大量按一定规则运动(变化)的微小物质在计算机上的生成和显示问题.Particle System的应用非常广泛,大的可以模拟原子弹爆炸,星云 ...

  5. cocos2d-x Tests讲解 Particle System(粒子系统)

    转载请注明出处: http://www.cnblogs.com/shangdahao/archive/2012/04/14/2447571.html 一.粒子系统简介: 粒子系统最早出现在80年代,主 ...

  6. POJ 1018 Communication System(贪心)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  7. 快速了解 Robot Operating System(ROS) 机器人操作系统

     http://www.ros.org/ 关于ROS About ROS http://www.ros.org/about-ros/ 机器人操作系统(ROS)是用于编写机器人软件的灵活框架.目的在简化 ...

  8. 信用评分卡Credit Scorecards (1-7)

      欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章 python风控评分卡建模和风控常识 https://study.163.com/course/introductio ...

  9. Unity3D学习笔记——组件之Effects(效果/特效)——Particle System(粒子系统)

    Effects:效果/特效. Particle System:粒子系统.可用于创建烟雾.气流.火焰.涟漪等效果. 在Unity3D 3.5版本之后退出了新的shuriken粒子系统:   添加组件之后 ...

随机推荐

  1. 一些小案例_C#

    下面是一些小的案例.(C#) 1,求一段数第n位 //1 1 2 3 5 8 求30位 //规律是前两位之和是第三位数, ;//定义第一位 ;//定义第二位 ;//总和 ; i < ; i++) ...

  2. 【react】当react框架遇上百度地图

      百度地图官方文档的使用指导是这样说的:在页面中引入<script type="text/javascript" src="http://api.map.baid ...

  3. [ActionScript 3.0] as3处理xml的功能和遍历节点

    as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象 ...

  4. DevOps - CI - Sonar

    Sonar 官方信息 https://www.sonarqube.org/ https://www.sonarqube.org/downloads/ https://docs.sonarqube.or ...

  5. Docker仓库(四)

    一.什么是仓库 仓库就是集中存放镜像的地方,分为公共仓库和私有仓库,一个容易混淆的概念是注册服务器,实际上注册服务器是存放仓库的具体服务器,一个注册服务器可以有多个仓库,而每个仓库下面有多个镜像 二. ...

  6. 学习推荐-Redis学习手册

    redis之旅: http://www.cnblogs.com/stephen-liu74/archive/2012/02/27/2370212.html

  7. Metasploit数据库问题汇总

    数据库在metaspoit中是相当重要的,当做一个大型渗透测试项目的时候,收集到的信息是相当大的,当和你的同伴一起协同作战的时候,你们可能 在不同的地方,所以数据共享很重要了!而且Metasploit ...

  8. 再学Java 之 interface的成员变量

    前言:最近在学多线程,写“哲学家就餐问题(Dining Philosophers)”的时候,需要定义一个全局的变量,即哲学家的人数.常用的做法是在其中一个类中定义一个static final的变量,然 ...

  9. Android中常见的对话框

    1. 普通对话框 public void click01(View view){ AlertDialog.Builder builder = new AlertDialog.Builder(this) ...

  10. 【JAVA SPRING】IOC与AOP

    IOC(注入)有三种类型: 构造函数注入: 属性注入: 接口注入: JAVA反射: JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法: 对于任意一个对象,都能够调用它的 ...