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的更多相关文章

  1. UVA 11078 Open Credit System(扫描 维护最大值)

    Open Credit System In an open credit system, the students can choose any course they like, but there ...

  2. UVa 11549 Open Credit System

    题意:给出n个数,找出两个整数a[i],a[j](i < j),使得a[i] - a[j]尽量大 从小到大枚举j,在这个过程中维护a[i]的最大值 maxai晚于ans更新, 可以看这个例子 1 ...

  3. Open Credit System(UVA11078)

    11078 - Open Credit System Time limit: 3.000 seconds Problem E Open Credit System Input: Standard In ...

  4. 【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 ...

  5. Open Credit System

    Open Credit SystemInput: Standard Input Output: Standard Output In an open credit system, the studen ...

  6. UVA Open Credit System Uva 11078

    题目大意:给长度N的A1.....An 求(Ai-Aj)MAX 枚举n^2 其实动态维护最大值就好了 #include<iostream> #include<cstdio> u ...

  7. Uva 11078 简单dp

    题目链接:http://uva.onlinejudge.org/external/110/11078.pdf a[i] - a[j] 的最大值. 这个题目马毅问了我,O(n^2)超时,记忆化一下当前最 ...

  8. UVA - 11400 Lighting System Design

    题文: You are given the task to design a lighting system for a huge conference hall. After doing a lot ...

  9. uva11078 - Open Credit System(动态维护关键值)

    这道题使用暴力解法O(n*n)会超时,那么用动态维护最大值可以优化到O(n).这种思想非常实用. #include<iostream> #include<cstdio> #in ...

随机推荐

  1. thinkphp的自动完成功能说明

    手册里有一句话很关键: 自动完成是ThinkPHP提供用来完成数据自动处理和过滤的方法,使用create方法创建数据对象的时候会自动完成数据处理. 这句话说明自动完成发生的时间是create()组建数 ...

  2. s表达式和json表达式

    s表达式 + 1 2 3普通表达式 1+2+3json表达式{ +:[1, 2, 3]}优点,一个运算符,无限个参数 s表达式 * (+ 1 2) 3普通表达式 1+(2*3)json表达式{ *:[ ...

  3. 转一篇讲camera的 mb好多年不搞3d 都忘光了

    Camera定义 游戏中,Camera用来向用户展示场景,Camera就像一个摄像机,摄像机里面的景象就是Camera的展示范围,如下图所示: 在3D空间中Camera被定义为一个位置,有一个单位“方 ...

  4. elcipse 中利用maven创建web工程

    如何创建: http://huxiaoheihei.iteye.com/blog/1766986 遇到的问题: 1: 如果spring MVC配置了 <servlet> <servl ...

  5. ACCESS 数据库使用配置调整解决方案

    分享到 一键分享 QQ空间 新浪微博 百度搜藏 人人网 腾讯微博 百度相册 开心网 腾讯朋友 百度贴吧 豆瓣网 搜狐微博 百度新首页 QQ好友 和讯微博 更多... 百度分享 64位服务器无法使用ac ...

  6. html一般标签、常用标签、表格

    body的属性: bgcolor               页面背景色 text                    文字颜色 topmargin            上边距 leftmargi ...

  7. mysql概要(十一)存储引擎

    1.数据库对同样的数据可以不同的方式存储和管理,每种方式对应一种引擎. 1.1定义: 2.引擎种类的特点:

  8. Differences between volume, partition and drive

    A drive is a physical block disk. For example: /dev/sda. A partition A drive can be divided into som ...

  9. C++——输入、输出和文件

    一.C++输入和输出概述 1.1.流和缓冲区 C++程序把输入和输出看作字节流.输入时,程序从输入流中抽取字节:输出时,程序将字节插入到输出流中.对于面相文本的程序,每个字节代表一个字符,更通俗地说, ...

  10. SDL2.0的VS开发环境搭建

    SDL2.0的VS开发环境搭建 [前言] 我是用的是VS2012,VS的版本应该大致一样. [开发环境搭建] >>>SDL2.0开发环境配置:1.从www.libsdl.org 下载 ...