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 ...
随机推荐
- HDU 4870 Rating 概率DP
Rating Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- Freebie - Utility Form: Generate Excel Report From SQL Query In Oracle Forms 6i And 11g
Sharing a form to generate Excel file report from SQL query in Oracle Forms. This form can be used i ...
- 面向对象--类库、委托、is和as运算符、泛型集合
类库: 其实就是一堆类文件,只是看不到这些类的源代码,保密性好. 优点:保密性好 缺点:如果这个方法不好用,使用者无法自己去更改它. 给的大多是dll文件.使用方法:引用右键,添加引用,浏览,选择到相 ...
- MYSQL写入数据时报错ERROR 1366 (HY000): Incorrect string value: '\xE8\x8B\xB1\xE5\xAF\xB8...' for c 插入中文不能插入
先把原先你创建的这个表删除,然后 CREATE TABLE IF NOT EXISTS tdb_goods( goods_id SMALLINT UNSIGNED PRIMARY KEY AUTO_I ...
- JQuery 选中Radio
<tr> <td> <input type="radio" name="rdb" value="启用" che ...
- win8和ubuntu双系统安装
做了一个windows和Ubuntu双系统,参考了一些文章.网上资料不少,我就不重复了. 虽然没什么难度,但是有些细节在装的时候需要注意.不然造成资料丢失,系统崩溃,你就得不偿失,需要折腾花费较长的时 ...
- 如何将自己开发的标签打成jar包
1: 在Myeclipse中新建一个java工程 2: 将你的标签处理器类统统都拷到工程里面, 将tld文件拷到META-INF里面 3:点击file里面的export,
- [转] Android获取Manifest中<meta-data>元素的值
转自: http://www.2cto.com/kf/201303/194824.html android 开发中: 在AndroidManifest.xml中,<meta-data> ...
- web设计经验<二>设计华丽的用户体验的6个热门技巧
你是否曾经下载了一个应用,却发现它“很难使用”?对于大多数智能手机用户来说,答案是肯定的. 有趣的是,每四个手机应用中就有一个应用在下载后被“打入冷宫”. 如果一个应用能够吸引一个人下载并且打开它,但 ...
- Git学习(1)Git 简介
Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件. Git ...