博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVa 11078 - Open Credit System
阅读量:7125 次
发布时间:2019-06-28

本文共 828 字,大约阅读时间需要 2 分钟。

  题目大意:给一个n个数的数组A[1...n],从中找出两个数A[i], A[j](i<j) 使得A[i]-A[j]的值最大。  

  首先用二重循环试了下,超时。对于每一个j, 只需找出左边最大的值就行了,因此从小到大枚举j,同时维护j左边的最大值lmax。

View Code
1 #include 
2 #include
3 #include
4 using namespace std; 5 6 int main() 7 { 8 #ifdef LOCAL 9 freopen("in", "r", stdin);10 #endif11 int T, x;12 scanf("%d", &T);13 while(T--)14 {15 int n;16 scanf("%d", &n);17 scanf("%d", &x);18 int lmax = x;19 int ans = INT_MIN;20 for(int i = 1; i < n; i++)21 {22 scanf("%d", &x);23 ans = max(ans, lmax-x);24 lmax = max(lmax, x);25 }26 printf("%d\n", ans);27 }28 return 0;29 }

 

转载于:https://www.cnblogs.com/xiaobaibuhei/archive/2013/04/10/3012585.html

你可能感兴趣的文章
asp记录集指针操作
查看>>
Memcached telnet端命令
查看>>
考试防刷新、切屏效果实现
查看>>
poj 2154 Color
查看>>
QT学习之forward declaration of 'struct Ui::xxx';invalid use of incomplete struct "Ui::Widget"
查看>>
Apc缓存Opcode(转)
查看>>
Enterprise Library系列文章目录(转载)
查看>>
程序与程序的交互--接口
查看>>
3.项目学习二
查看>>
[hihoCoder] 题外话·堆
查看>>
Drupal中常用一些模块
查看>>
当下大部分互联网创业公司为什么都愿意采用增量模型来做开发?
查看>>
[Windows Azure] Windows Azure SQL Database library
查看>>
SpringBoot扫描数据库配置的定时任务,根据cron定时刷新数据库数据保证任务数据最新...
查看>>
Vue / keep-alive使用
查看>>
SQL学习之使用常用函数处理数据
查看>>
JavaScript之面向对象学九(原型式继承和寄生式继承)
查看>>
memcached(五)--源码分析,启动
查看>>
实践2
查看>>
CHUI类
查看>>