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

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. int num[];
  5. int maxnum,ans;
  6.  
  7. int main()
  8. {
  9. int T,N,i,j;
  10. scanf("%d",&T);
  11. while(T--)
  12. {
  13. scanf("%d",&N);
  14. scanf("%d%d",&num[],&num[]);
  15. maxnum=num[]>num[]?num[]:num[];
  16. ans=num[]-num[];
  17. for(i=;i<N;i++)
  18. {
  19. scanf("%d",&num[i]);
  20. ans=max(ans,maxnum-num[i]);
  21. maxnum=max(maxnum,num[i]);
  22. }
  23. printf("%d\n",ans);
  24. }
  25. return ;
  26. }

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. Select count(*)、Count(1)、Count(0)的区别和执行效率比较

    记得很早以前就有人跟我说过,在使用count的时候要用count(1)而不要用count(*),因为使用count(*)的时候会对所有的列进行扫描,相比而言count(1)不用扫描所有列,所以coun ...

  2. elasticsearch插件一head插件安装详解

    elasticsearch-head是一个用来浏览.与Elastic Search簇进行交互的web前端展示插件. elasticsearch-head插件主要用途: elasticsearch主要有 ...

  3. underscore.js源码研究(6)

    概述 很早就想研究underscore源码了,虽然underscore.js这个库有些过时了,但是我还是想学习一下库的架构,函数式编程以及常用方法的编写这些方面的内容,又恰好没什么其它要研究的了,所以 ...

  4. Swift 里字符串(十一)OC 字符串和 Swift 字符串的转换

     to OC func _bridgeToObjectiveCImpl() -> AnyObject { if _guts.isSmall { return _guts.asSmall.wit ...

  5. DockerFile(保你会版本)(七)

    一.什么是dockerfile Dockerfile是一个文本格式的配置文件,用户可以使用Dockerfile自定义快速创建属于自己的镜像,Dockerfile是通过很多的参数指令编写的文件,通过do ...

  6. WIN10安装scrapy/channels等不成功的解决方式

    问题 在Win10机器上,不管是安装scrapy还是channels,都需要安装一个包,叫做twisted.正是这个twisted,导致出现一系列的奇葩错误,让我一度以为我的Pycharm坏了,还改了 ...

  7. Java异常处理设计(二)

    考虑对JDK的底层堆栈信息进行处理,一种是重写JDK的Throwable,另一种是在原错误堆栈信息上进行“二次加工”.目前这两种方式我都实现了,效果非常好. 这篇文章主要记录对错误堆栈进行“二次加工” ...

  8. i=i+1,i+=1,i++哪个执行效率最高?为什么?

    (1)i=i+1最低,它的执行过程如下:读取右i的地址i+1读取左i的地址将右值传给左边的i(编译器并不认为左右i的地址相同)(2)i+=1其次,它的执行过程如下:读取左x的地址i+1将得到的值传给i ...

  9. Android的Fragment的第一种声明方式

    Android的Frangment的第一种声明方式 实际效果图如下: 项目结构图如下: fragment1: package com.demo.fragementfirst; import andro ...

  10. flex布局下, 内容改变 不重新渲染问题

    当使用flex布局时,flex内元素包含的内容改变时,浏览器不会进行重新渲染, 答案引用 http://stackoverflow.com/questions/23474191/flexbox-hei ...