南阳oj S + T
来源:互联网 发布:美工电脑是什么意思 编辑:程序博客网 时间:2024/05/20 16:36
自己写,tle了,转载一下大佬的题解学习
转自
http://blog.csdn.net/chang_mu/article/details/29686723
解法一
#include <stdio.h> #define maxn 100000 + 2 long long arr[maxn], ans, temp; struct Node{ long long val; int at; } min[maxn]; //存储下标i到n的最小值和其下标 int main(){ int t, n, x, y; scanf("%d", &t); while(t--){ scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%lld", arr + i); min[n].val = arr[n]; min[n].at = n; for(int i = n - 1; i; --i){ if(arr[i] <= min[i+1].val){ min[i].val = arr[i]; min[i].at = i; }else min[i] = min[i+1]; } ans = arr[1] - arr[2]; x = 1; y = 2; temp = arr[1] - 1; for(int i = 1; i < n; ++i){ if(arr[i] > temp){ temp = arr[i]; if(temp - min[i+1].val > ans){ ans = temp - min[i+1].val; x = i; y = min[i+1].at; } } } printf("%lld %d %d\n", ans, x, y); } return 0; }
解法二
#include <stdio.h> int main(){ int t, n, ans, x, y, max, temp, xx, val; scanf("%d", &t); while(t--){ scanf("%d", &n); ans = max = -10000000; xx = x = 1; y = 2; for(int i = 1; i <= n; ++i){ scanf("%d", &temp); if((val = max - temp) > ans){ ans = val; x = xx; y = i; } if(temp > max){ max = temp; xx = i; } } printf("%d %d %d\n", ans, x, y); } return 0; }
阅读全文
0 0
- 南阳oj S + T
- 南阳OJ
- 南阳oj
- 南阳oj
- 南阳OJ
- 南阳oj 整数性质
- 复杂度 743 南阳oj
- 南阳 oj 147
- 01串---南阳OJ
- 南阳oj 字符串替换
- 南阳 oj 6174问题
- 南阳OJ 背包问题
- 南阳 oj 兰州烧饼
- 南阳oj 房间安排
- 南阳OJ~~水仙花数
- 南阳oj~~素数
- 南阳OJ 成绩转换
- 南阳OJ 517:最小公倍数
- 代码规范 : 集合处理
- Resource Acquisition Is Initialization(RAII)
- 3.Longest Substring Without Repeating Characters
- MongoDB的基本使用
- poj 2236
- 南阳oj S + T
- R之箱线图
- 设计模式知识连载(26)---模板方法模式:
- c++派生类与继承
- 生活习惯
- HTTP协议
- ubuntu 16.04 theano gpu
- LeetCode Generate Parentheses
- R语言System {base}函数