Open Credit System(UVA11078)
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 |
题意:给一个长度为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)的更多相关文章
- 关于system(”pause“);的作用和意义
注意:不要再return 的语句之后加,那样就执行不到了. system() 是调用系统命令:pause 暂停命令: 如果加有 system(”pause“): 这样在运行到此处时,会显示“Pres ...
- uva11078 - Open Credit System(动态维护关键值)
这道题使用暴力解法O(n*n)会超时,那么用动态维护最大值可以优化到O(n).这种思想非常实用. #include<iostream> #include<cstdio> #in ...
- UVA 11078 Open Credit System(扫描 维护最大值)
Open Credit System In an open credit system, the students can choose any course they like, but there ...
- cocos2d-x:Particle System(粒子系统)
一.粒子系统简介: 粒子系统最早出现在80年代,主要用于解决由大量按一定规则运动(变化)的微小物质在计算机上的生成和显示问题.Particle System的应用非常广泛,大的可以模拟原子弹爆炸,星云 ...
- cocos2d-x Tests讲解 Particle System(粒子系统)
转载请注明出处: http://www.cnblogs.com/shangdahao/archive/2012/04/14/2447571.html 一.粒子系统简介: 粒子系统最早出现在80年代,主 ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- 快速了解 Robot Operating System(ROS) 机器人操作系统
http://www.ros.org/ 关于ROS About ROS http://www.ros.org/about-ros/ 机器人操作系统(ROS)是用于编写机器人软件的灵活框架.目的在简化 ...
- 信用评分卡Credit Scorecards (1-7)
欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章 python风控评分卡建模和风控常识 https://study.163.com/course/introductio ...
- Unity3D学习笔记——组件之Effects(效果/特效)——Particle System(粒子系统)
Effects:效果/特效. Particle System:粒子系统.可用于创建烟雾.气流.火焰.涟漪等效果. 在Unity3D 3.5版本之后退出了新的shuriken粒子系统: 添加组件之后 ...
随机推荐
- MVC 视图不使用模板页的两种方法
直接对view页面的Layout值设置null @{ Layout = null;//"~/Views/Shared/_Layout.cshtml"; } 对_ViewStart. ...
- MQ的demo
public class WorkTest { @Test public void send() throws Exception{ //获取连接 Connection conn = ...
- Fusioncharts的数字格式化
1. 小数点位数格式化 <chart ... decimals='2' > Eg.数值12.432, 13.4 and 13,使用<chart ... decimals= ...
- tomcat设置默认欢迎页、server.xml配置文件中的标签理解
一:要求:输入网址,不加文件名便可以访问默认页面 (1)项目中只有静态文件 方法:更改tomcat下的conf目录下的web.xml文件,如下图: <welcom-file-list>元素 ...
- Python小白学习之路(二十五)—【装饰器的应用】
通过一个任务来加深对装饰器的理解和应用 回顾:装饰器的框架 def timmer(func): def wrapper(): func() return wrapper 任务:给以下正在运行的程序加一 ...
- [工具]Tomcat CVE-2017-12615 远程代码执行
工具: K8_TocmatExp编译: VS2012 C# (.NET Framework v2.0)组织: K8搞基大队[K8team]作者: K8拉登哥哥博客: http://qqhack8.b ...
- 如何在Ubuntu 14.04上利用jexus搭建支持php+mysql数据库的网站服务
准备部分:sudo apt-get update sudo apt-get install unzip -y第一部分:安装jexus 在终端运行以下命令 cd /tm ...
- Java获取随机数获取制定范围指定个数不重复的随机数
一.JDK中提供的两种方式 1.Math类中的random()方法public static double random()返回带正号的 double 值,该值大于等于 0.0 且小于 1.0 [0. ...
- Identity Server4学习系列四之用户名密码获得访问令牌
1.简介 Identity Server4支持用户名密码模式,允许调用客户端使用用户名密码来获得访问Api资源(遵循Auth 2.0协议)的Access Token,MS可能考虑兼容老的系统,实现了这 ...
- mysql的sql执行计划详解(非常有用)
以前没有怎么了解mysql执行计划,以及sql 优化方面,今天算学习了. https://blog.csdn.net/heng_yan/article/details/78324176 https:/ ...