【BZOJ3043】IncDec Sequence
2013-01-23 13:54
387 查看
3043: IncDec Sequence
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 13 Solved: 6
[Submit][Status][Discuss]
Description
给定一个长度为n的数列{a1,a2...an},每次可以选择一个区间[l,r],使这个区间内的数都加一或者都减一。问至少需要多少次操作才能使数列中的所有数都一样,并求出在保证最少次数的前提下,最终得到的数列有多少种。
Input
第一行一个正整数n接下来n行,每行一个整数,第i+1行的整数表示ai。
。
Output
第一行输出最少操作次数第二行输出最终能得到多少种结果
Sample Input
41
1
2
2
Sample Output
12
HINT
对于100%的数据,n=100000,0<=ai<2147483648Code
#include <cstdio> #define maxn 1000000 int a[maxn], b[maxn], n, i; long long x = 0, y = 0, ans; using namespace std; int main() { scanf("%d", &n); b[1] = 0; for (i = 1; i <= n; i++) scanf("%d", &a[i]); for (i = 2; i <= n; i++) { b[i] = a[i] - a[i - 1]; if (b[i] > 0) x += b[i]; else y -= b[i]; } if (x > y) {printf("%lld\n", x); ans = x - y;} else {printf("%lld\n", y); ans = y - x;} printf("%lld\n", ans + 1); return 0; }
相关文章推荐
- bzoj 3043 wikioi 2498 IncDec Sequence
- [BZOJ 3043]IncDec Sequence
- 【BZOJ3043】IncDec Sequence 乱搞
- BZOJ 3043 IncDec Sequence 差分
- BZOJ 3043: IncDec Sequence
- bzoj 3043: IncDec Sequence 差分
- bzoj 3043: IncDec Sequence 模拟
- 差分【bzoj3043】IncDec Sequence
- [BZOJ3043] IncDec Sequence
- BZOJ系列3043《IncDec Sequence》题解
- bzoj3043 IncDec Sequence
- 【BZOJ 3043】 3043: IncDec Sequence (差分)
- 3043: IncDec Sequence
- 【BZOJ】【P3043】【IncDec Sequence】【题解】【差分】
- 3043: IncDec Sequence (中位数)
- 3043: IncDec Sequence
- 2498 IncDec Sequence
- CODEVS P2498 IncDec Sequence
- bzoj3043: IncDec Sequence 差分
- [Poetize6] IncDec Sequence