UVa 11549 Open Credit System
题意:给出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的更多相关文章
- UVA 11078 Open Credit System(扫描 维护最大值)
Open Credit System In an open credit system, the students can choose any course they like, but there ...
- 【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(UVA11078)
11078 - Open Credit System Time limit: 3.000 seconds Problem E Open Credit System Input: Standard In ...
- Open Credit System
Open Credit SystemInput: Standard Input Output: Standard Output In an open credit system, the studen ...
- Uva----------(11078)Open Credit System
Open Credit System Input:Standard Input Output: Standard Output In an open credit system, the studen ...
- Floyd判圈算法 UVA 11549 - Calculator Conundrum
题意:给定一个数k,每次计算k的平方,然后截取最高的n位,然后不断重复这两个步骤,问这样可以得到的最大的数是多少? Floyd判圈算法:这个算法用在循环问题中,例如这个题目中,在不断重复中,一定有一个 ...
- UVA Open Credit System Uva 11078
题目大意:给长度N的A1.....An 求(Ai-Aj)MAX 枚举n^2 其实动态维护最大值就好了 #include<iostream> #include<cstdio> u ...
- 【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 ...
- Uva 11549 - Calculator Conundrum 找规律加map
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
随机推荐
- CDR是什么?CorelDRAW矢量绘图
CorelDRAW是矢量绘图软件 CorelDRAW Graphics Suite是加拿大Corel公司的平面设计软件: CorelDRAW 非凡的设计能力广泛地应用于商标设计.标志制作.模型绘制.插 ...
- Asp.net Core 源码-SessionExtensions
using Microsoft.AspNetCore.Http; using Newtonsoft.Json; namespace SportsStore.Infrastructure { publi ...
- 补充01 Django 类视图
视图 函数视图[Function Base View] 以函数的方式定义的视图称为函数视图,函数视图便于理解.但是遇到一个视图对应的路径提供了多种不同HTTP请求方式的支持时,便需要在一个函数中编写不 ...
- 洛谷P1941飞扬的小鸟 完全背包
思维难度不大,就是有许多细节要注意. 1.不能开滚动数组. 2.要特判飞过天花板的情况. Code: #include<cstdio> #include<algorithm> ...
- 洛谷P1120 小木棍 [数据加强版]搜索
玄学剪支,正好复习一下搜索 感觉搜索题的套路就是先把整体框架打出来,然后再一步一步优化剪枝 1.从maxv到sumv/2枚举长度(想一想,为什么) 2. 开一个桶,从大到小开始枚举 3. 在搜索中,枚 ...
- Nginx配置udp/tcp代理
#编译 ./configure --prefix=/servyouapp/nginx --with-stream --with-http_stub_status_module #nginx.conf部 ...
- Selenium+Python+jenkins搭建web自动化测测试框架
python-3.6.2 chrome 59.0.3071.115 chromedriver 2.9 安装python https://www.python.org/downloads/ (Wind ...
- Java包名称中通配符的含义
"com.abc 表示的意义为:系统从com.abc这个包及其子孙包扫描组件 "com.abc.* 表示的意义为:系统从com.abc这个包的子孙包扫描组件
- Mysql 忘记数据库密码
windows下忘记MySQL密码的修改方法 1.关闭正在运行的Mysql服务: A.命令下运行 net stop mysql B.找到mysql服务停止mysql的服务 C.在任务管理器中结束M ...
- leetCode笔记--binary tree
993. Cousins in Binary Tree In a binary tree, the root node is at depth 0, and children of each dept ...