题意:给出n个数,找出两个整数a[i],a[j](i < j),使得a[i] - a[j]尽量大

从小到大枚举j,在这个过程中维护a[i]的最大值

maxai晚于ans更新,

可以看这个例子

1 8 9 10 11

正确的应该是-1

如果更早更新的话,算出来就是0

用数组来存的

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int a[maxn];
int n; int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i = ;i < n;i++) scanf("%d",&a[i]);
int ans = a[] - a[];
int maxai = a[];
for(int j = ;j < n;j++){
ans = max(ans,maxai - a[j]);
maxai = max(maxai,a[j]);
// printf("j = %d maxai = %d ans = %d\n",j,maxai,ans);
}
printf("%d\n",ans);
}
return ;
}

边读边算的

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n); int x,y,ans;
scanf("%d %d",&x,&y);
ans = x-y;
int maxai = x;
for(int i = ;i<n;i++){
scanf("%d",&x);
ans = max(ans,maxai - x);
maxai = max(maxai,x);
}
printf("%d\n",ans);
}
return ;
}

UVa 11549 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 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 ...

  3. Open Credit System(UVA11078)

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

  4. Open Credit System

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

  5. Uva----------(11078)Open Credit System

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

  6. Floyd判圈算法 UVA 11549 - Calculator Conundrum

    题意:给定一个数k,每次计算k的平方,然后截取最高的n位,然后不断重复这两个步骤,问这样可以得到的最大的数是多少? Floyd判圈算法:这个算法用在循环问题中,例如这个题目中,在不断重复中,一定有一个 ...

  7. UVA Open Credit System Uva 11078

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

  8. 【set&&sstream||floyed判环算法】【UVa 11549】Calculator Conundrum

    CALCULATOR CONUNDRUM Alice got a hold of an old calculator that can display n digits. She was bored ...

  9. Uva 11549 - Calculator Conundrum 找规律加map

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. bootstrap初用新得2

    ##具体实现 1. 宽度无限的背景和始终居中的主题内容:   首先是背景要用一个div1来做out-background,然后div1的兄弟元素div2来做container.对out-backgro ...

  2. Mac 查看 剪贴板/剪切板/粘贴板 内容与格式

    命令行形式 osascript -e 'clipboard info' GUI 形式 Finder->编辑->显示剪贴板 图示:

  3. springboot-注解讲解

    @Configuration:声明我们JdbcConfig是一个配置类 @PropertySource:指定属性文件的路径是:classpath:jdbc.properties 通过@Value为属性 ...

  4. Windows Server 2012安装.net framework3.5(转)

    1.先下载WIN2012R2安装NET3.5的专用数据源 https://pan.baidu.com/s/1bqiUTyR 提取码h09k 并解压,比如解压到桌面,解压后的路径为C:\Users\Ad ...

  5. Matrix(坑)

    https://github.com/florent37/Android-3D-Layout

  6. Git 本地项目添加多个远程仓库

    做了一个小玩意儿,是在 码云 上做的仓储: 还想同时放在 github 上做个备份: 就在 github 上创建了一个新的项目地址: 可以看出,官方给了三种导入方式: 1.创建一个新的项目: 2.推送 ...

  7. Selenium 安装与配置及webdriver的API与定位元素

    1. selenium安装命令行 C:\Users\wu>cd /d E:\soft\python3.6\Scripts E:\soft\python3.6\Scripts>pip3 in ...

  8. npm run build 打包项目,图片等资源使用相对路径会出现路径错误的问题

    在build下的utils.js中,3使用 ‘vue-style-loader’ 依赖的地方添加 publicPath: '../../' , 如图:

  9. PHP 闭包之变量作用域

      在项目中,难免会遇到闭包的形式,那么在闭包中,变量的作用域到底是怎么样的呢.下面有几个简单的例子. e1 function test_1() { $a = 'php'; $func = funct ...

  10. github发布博客

    创建github项目:  名字为:{{你的帐号}}.github.io clone项目,创建并提交推送一个index页面 如: <!DOCTYPE html> <html> & ...