首页 > 其他 > 详细

uva 11078 - Open Credit System(水题)

时间:2014-01-23 08:05:51      阅读:361      评论:0      收藏:0      [点我收藏+]

题目链接:uva 11078 - Open Credit System


题目大意:给出n个数,找出两个数之间差的最大值,要求num[i] - num[j](i < j)


解题思路:维护最大值Max,每次读取一个数时用Max - c,维护ans。


#include <stdio.h>
#include <algorithm>

using namespace std;
const int INF = 0x3f3f3f3f;

int main() {
	int cas, n;
	scanf("%d", &cas);
	while (cas--) {
		scanf("%d", &n);
		int ans = -INF, Max = -INF, c;
		for (int i = 0; i < n; i++) {
			scanf("%d", &c);
			ans = max(ans, Max - c);
			Max = max(Max, c);
		}
		printf("%d\n", ans);
	}
	return 0;
}


uva 11078 - Open Credit System(水题)

原文:http://blog.csdn.net/keshuai19940722/article/details/18648761

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!