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粒子系统: 添加组件之后 ...
随机推荐
- JSOI2010 缓存交换
题目链接:戳我 考虑一个贪心--就是每次我们都选择队列里面之后最晚加入的元素弹出. 维护一个nxt数组就行了. 特判一下之后不会再加入的元素. 代码如下: #include<iostream&g ...
- 2019/4/23 todolist
近期的任务单子大概是这样吧 bjoi2019改完,写题解 hnoi2019改一些,写题解 找3道网络流写写 写一场agc,写题解 找2道简单计算几何写写
- 一分钟学会git
首先 克隆 源码地址 git clone git://github.com/jquery/jquery.git 更新 git pull查看状态 git status暂存所有(注意 . 表示全部暂存) ...
- 表单控件 css的三中引入方式css选择器
1. 表单控件: 单选框 如果两个单选的name值一样,会产生互斥效果 <p> <!--单选框--> 男<input type="radio" nam ...
- Iframe高度自适应(兼容IE/Firefox、同域/跨域)
在实际的项目进行中,很多地方可能由于历史原因不得不去使用iframe,包括目前正火热的应用开发也是如此. 随之而来的就是在实际使用iframe中,会遇到iframe高度的问题,由于被嵌套的页面长度不固 ...
- (干货) Android实现ImageVIew多点触控及双击缩放
支持多点触控,放大自由移动,双击可以放大缩小.直接上代码: package com.cbt.view; import android.content.Context; import android.g ...
- Consul集群搭建
一.集群搭建 准备三台机器 需要开启的端口,8300, 8301, 8500, 8600 机器1: 172.16.106.201 ./consul agent -server -bootstrap-e ...
- android开发学习——day2
简单了解了android stdio的操作方式,今天着手于探究活动(Activity) 了解了基本活动与手动创建活动的方法,了解了onCreate()方法,了解了创建和加载页面布局(layout) 新 ...
- CentOS安装Nginx 以及日志管理
环境:CentOS-6.4 Nginx版本:nginx-1.6.2.tar Linux连接工具:XShell VMWare虚拟机上准备两台CentOS: 两台机器做同样操作(后边做负载均衡.高可用的时 ...
- Java 中的队列 Queue
一.队列的定义 我们都知道队列(Queue)是一种先进先出(FIFO)的数据结构,Java中定义了java.util.Queue接口用来表示队列.Java中的Queue与List.Set属于同一个级别 ...