Uva----------(11078)Open Credit System
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'thstudent.
All these integers have absolute values less than 150000. If i < j, then i'thstudent 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 |
这道题,就是给出一系列的有序的数,比如a[0] a[1],a[2],a[3].....a[i]....a[n]. 要你求出a[i]-a[j]的最大值(注意i<j )
而且数据规模也是十万加的.....,可想而知,朴树的算法是会超时..
采用动态规划的思想...
先逐渐求出区间的最大值,注意每一次扩展时,都进行一次比较...
代码如下:
#include<cstdio>
#include<cstring>
const int maxn=;
int aa[maxn];
inline int max(int a,int b){
return a>b?a:b;
} int main(){
int n,m;
//freopen("test.in","r",stdin);
scanf("%d",&n);
while(n--){
scanf("%d",&m);
for(int i=;i<m;i++)
scanf("%d",aa+i);
int cnt=aa[]-aa[];
int maxc=aa[];
for(int i=;i<m;i++){
cnt=max(cnt,maxc-aa[i]);
maxc=max(maxc,aa[i]);
}
printf("%d\n",cnt);
}
return ;
}
进一步优化之后的
代码:
#include<cstdio>
#include<cstring>
const int maxn=;
inline int max(int a,int b){
return a>b?a:b;
}
int main(){
int n,m;
int b,c;
int ans;
freopen("test.in","r",stdin);
scanf("%d",&n);
while(n--){
scanf("%d",&m);
scanf("%d",&b);
ans =-;
for(int i=;i<m;i++){
scanf("%d",&c);
ans=max(ans,b-c);
b=max(b,c);
}
printf("%d\n",ans);
}
return ;
}
Uva----------(11078)Open Credit System的更多相关文章
- UVA 11078 Open Credit System(扫描 维护最大值)
Open Credit System In an open credit system, the students can choose any course they like, but there ...
- UVa 11549 Open Credit System
题意:给出n个数,找出两个整数a[i],a[j](i < j),使得a[i] - a[j]尽量大 从小到大枚举j,在这个过程中维护a[i]的最大值 maxai晚于ans更新, 可以看这个例子 1 ...
- Open Credit System(UVA11078)
11078 - Open Credit System Time limit: 3.000 seconds Problem E Open Credit System Input: Standard In ...
- 【UVA 11078】BUPT 2015 newbie practice #2 div2-A -Open Credit System
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/A In an open credit system, the ...
- Open Credit System
Open Credit SystemInput: Standard Input Output: Standard Output In an open credit system, the studen ...
- UVA Open Credit System Uva 11078
题目大意:给长度N的A1.....An 求(Ai-Aj)MAX 枚举n^2 其实动态维护最大值就好了 #include<iostream> #include<cstdio> u ...
- Uva 11078 简单dp
题目链接:http://uva.onlinejudge.org/external/110/11078.pdf a[i] - a[j] 的最大值. 这个题目马毅问了我,O(n^2)超时,记忆化一下当前最 ...
- UVA - 11400 Lighting System Design
题文: You are given the task to design a lighting system for a huge conference hall. After doing a lot ...
- uva11078 - Open Credit System(动态维护关键值)
这道题使用暴力解法O(n*n)会超时,那么用动态维护最大值可以优化到O(n).这种思想非常实用. #include<iostream> #include<cstdio> #in ...
随机推荐
- sql 增加字段
ALTER TABLE [dt_article_goods] ADD [goods_id] int DEFAULT 0
- Heap and HashHeap
Heap 堆(英语:Heap)是计算机科学中一类特殊的数据结构的统称.堆通常是一个可以被看做一棵树的数组对象.在队列中,调度程序反复提取队列中第一个作业并运行,因为实际情况中某些时间较短的任务将等待很 ...
- STORM_0001_用vmware拷贝出三个相同的ubuntu搭建小的zookeeper集群
第一次配置zookeeper的集群 因为想运行storm必须搭建集群在自己的电脑上拷贝了自己的ubuntu虚拟机采用的是vmware给虚拟机分配的地址三个机器的配置基本上一样除了myid这个文件看了这 ...
- 让WinForm窗体的大小固定,不能调整大小
窗体FormBorderStyle属性设置为:FixedSingle,再把最大化禁用就可以了
- const 与 readonly 知多少
const与readonly 很像,都是将变量声明为只读,且在变量初始化后就不可改写.那么,const与readonly 这两个修饰符到底区别在什么地方呢?其实,这个牵扯出C#语言中两种不同的常量类型 ...
- jQuery细节总结
1.mouseover和mouseenter 区别 mouseenter指鼠标进入元素时触发,鼠标在元素子元素上不触发. mouseover指鼠标进入元素时触发,在元素进入子元素会触发. 在此引用一个 ...
- Linux配置apache等系列
1.Linux下安装.配置PHP环境 2.ubuntu12.0.4安装apache, php ,mysql 3 CentOs中mysql的安装与配置
- iOS - Delegate 代理
1.Delegate 1.1 协议 协议:是多个类共享的一个方法列表.协议中列出的方法没有相应的实现,计划由其他人来实现.协议中列出的方法,有些是可以选择实现,有些是必须实现. 1>.如果你定义 ...
- 禁止ubuntu的super快捷键
在mac上安装了ubuntu虚拟机, 但是发现command健(ubuntu中叫super健)被系统占用了, 习惯了command健的同学来说非常不方便, 如何禁用默认的command健呢? You ...
- uiZjs入门
具体基础的用法,可先看下这个文件做下了解,地址:http://files.cnblogs.com/dachuang/uizjs.rar 请先看完上面的文件,不然下面的可能看不懂,当然你要是之前了解过的 ...