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

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

maxai晚于ans更新,

可以看这个例子

1 8 9 10 11

正确的应该是-1

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

用数组来存的

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<stack>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<algorithm>
  11. using namespace std;
  12.  
  13. typedef long long LL;
  14. const int INF = (<<)-;
  15. const int mod=;
  16. const int maxn=;
  17.  
  18. int a[maxn];
  19. int n;
  20.  
  21. int main(){
  22. int T;
  23. scanf("%d",&T);
  24. while(T--){
  25. scanf("%d",&n);
  26. for(int i = ;i < n;i++) scanf("%d",&a[i]);
  27. int ans = a[] - a[];
  28. int maxai = a[];
  29. for(int j = ;j < n;j++){
  30. ans = max(ans,maxai - a[j]);
  31. maxai = max(maxai,a[j]);
  32. // printf("j = %d maxai = %d ans = %d\n",j,maxai,ans);
  33. }
  34. printf("%d\n",ans);
  35. }
  36. return ;
  37. }

边读边算的

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<stack>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<algorithm>
  11. using namespace std;
  12.  
  13. typedef long long LL;
  14. const int INF = (<<)-;
  15. const int mod=;
  16. const int maxn=;
  17.  
  18. int main(){
  19. int T;
  20. scanf("%d",&T);
  21. while(T--){
  22. int n;
  23. scanf("%d",&n);
  24.  
  25. int x,y,ans;
  26. scanf("%d %d",&x,&y);
  27. ans = x-y;
  28. int maxai = x;
  29. for(int i = ;i<n;i++){
  30. scanf("%d",&x);
  31. ans = max(ans,maxai - x);
  32. maxai = max(maxai,x);
  33. }
  34. printf("%d\n",ans);
  35. }
  36. return ;
  37. }

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. CDR是什么?CorelDRAW矢量绘图

    CorelDRAW是矢量绘图软件 CorelDRAW Graphics Suite是加拿大Corel公司的平面设计软件: CorelDRAW 非凡的设计能力广泛地应用于商标设计.标志制作.模型绘制.插 ...

  2. Asp.net Core 源码-SessionExtensions

    using Microsoft.AspNetCore.Http; using Newtonsoft.Json; namespace SportsStore.Infrastructure { publi ...

  3. 补充01 Django 类视图

    视图 函数视图[Function Base View] 以函数的方式定义的视图称为函数视图,函数视图便于理解.但是遇到一个视图对应的路径提供了多种不同HTTP请求方式的支持时,便需要在一个函数中编写不 ...

  4. 洛谷P1941飞扬的小鸟 完全背包

    思维难度不大,就是有许多细节要注意. 1.不能开滚动数组. 2.要特判飞过天花板的情况. Code: #include<cstdio> #include<algorithm> ...

  5. 洛谷P1120 小木棍 [数据加强版]搜索

    玄学剪支,正好复习一下搜索 感觉搜索题的套路就是先把整体框架打出来,然后再一步一步优化剪枝 1.从maxv到sumv/2枚举长度(想一想,为什么) 2. 开一个桶,从大到小开始枚举 3. 在搜索中,枚 ...

  6. Nginx配置udp/tcp代理

    #编译 ./configure --prefix=/servyouapp/nginx --with-stream --with-http_stub_status_module #nginx.conf部 ...

  7. Selenium+Python+jenkins搭建web自动化测测试框架

    python-3.6.2 chrome 59.0.3071.115 chromedriver 2.9 安装python https://www.python.org/downloads/  (Wind ...

  8. Java包名称中通配符的含义

    "com.abc 表示的意义为:系统从com.abc这个包及其子孙包扫描组件 "com.abc.* 表示的意义为:系统从com.abc这个包的子孙包扫描组件

  9. Mysql 忘记数据库密码

    windows下忘记MySQL密码的修改方法 1.关闭正在运行的Mysql服务: A.命令下运行   net stop mysql B.找到mysql服务停止mysql的服务 C.在任务管理器中结束M ...

  10. leetCode笔记--binary tree

    993. Cousins in Binary Tree In a binary tree, the root node is at depth 0, and children of each dept ...