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粒子系统: 添加组件之后 ...
随机推荐
- UWP Background过渡动画
首先说两件事: 1.大爆炸我还记着呢,先欠着吧... 2.博客搬家啦,新地址:https://blog.ultrabluefire.cn/ ==========下面是正文========== 前些日子 ...
- Vue + Bootstrap 制作炫酷个人简历(二)
没想到隔了这么久才来更新. 用vue做简历,不是非常适合,为什么呢. 因为简历没什么数据上的操作,一般都是静态的内容. 不过都说了用Vue来做,也只能强行续命了. 这里是我做好的成品 非一般简历 由 ...
- Liferay7 BPM门户开发之2: BPMN 2.0 规范入门 (Activiti BPMN extensions)
Liferay最大的问题是BPM弱,如果做企业开发,BPM必不可少,所以直入主题,做个BPMN2入门. 本文参考地址:http://activiti.org/userguide/index.html# ...
- 利用django-simple-captcha生成验证码
参考文档 http://django-simple-captcha.readthedocs.io/en/latest/ django支持1.7+ 1.安装 pip install django-sim ...
- git常用命令(todo...)
git init在目录中执行 git init,就可以创建一个 Git 仓库 git add test.javagit add 命令可将该文件添加到缓存(暂存区) git commit test.ja ...
- easyui datebox 只选择月份的方法
easyui datebox 只选择月份的方法 效果如下图: 代码如下: <html > <head> <meta charset="utf-8"&g ...
- android app性能优化大汇总
这里根据网络上各位大神已经总结的知识内容做一个大汇总,作为记录,方便后续“温故知新”. 性能指标: (1)使用流畅度: 图片处理器每秒刷新的帧数(FPS),可用来指示页面是否平滑的渲染.高的帧率可以 ...
- 使用Java客户端对Redis进行操作
一.背景 上篇文章我们介绍了如何在centos7下面进行安装单机版redis以及redis集群.这篇文章,我们来聊一聊如何使用java客户端来进行操作redis.我们知道redis的java客户端有很 ...
- 计数排序/Counting Sort
计数排序的算法思想: 对于每一个元素x,只要确定了元素x有多少个比它小的元素,那么就可以知道其最终的位置. 记输入数组为A[n],存放最后排序输出的数组为B[n],提供临时存储空间的中间数组记为C[k ...
- Vue + Element UI 实现权限管理系统 前端篇(五):国际化实现
国际化支持 1.安装依赖 执行以下命令,安装 i18n 依赖. yarn add vue-i18n $ yarn add vue-i18n yarn add v1.9.4 warning packag ...