标签:deb map ddd sum 数据 rdd str limits amp
Description
Input
Output
Sample Input
Sample Output
Hint
Hint Huge input, scanf is recommended.
直接遍历然后不断更新下标和最大值~
//Asimple //#include <bits/stdc++.h> #include <iostream> #include <sstream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <cctype> #include <cstdlib> #include <stack> #include <cmath> #include <set> #include <map> #include <string> #include <queue> #include <limits.h> #include <time.h> #define INF 0xfffffff #define mod 1000000 #define swap(a,b,t) t = a, a = b, b = t #define CLS(a, v) memset(a, v, sizeof(a)) #define debug(a) cout << #a << " = " << a <<endl #define abs(x) x<0?-x:x #define srd(a) scanf("%d", &a) #define src(a) scanf("%c", &a) #define srs(a) scanf("%s", a) #define srdd(a,b) scanf("%d %d",&a, &b) #define srddd(a,b,c) scanf("%d %d %d",&a, &b, &c) #define prd(a) printf("%d\n", a) #define prdd(a,b) printf("%d %d\n",a, b) #define prs(a) printf("%s\n", a) #define prc(a) printf("%c", a) using namespace std; typedef long long ll; const int maxn = 10001; int n, m, num, T, k, len, ans, sum; int edx, edy, stx, sty; int dp[1000001]; int a[maxn];void input() { while( ~srd(n) && n ) { sum = 0; for(int i=0; i<n; i++) { srd(a[i]); } int inds = 0; int inde = 0, t = 0; int Maxsum = -INF; int sum = 0; for(int i=0; i<n; i++) { if( sum < 0 ) { sum = a[i]; t = i; } else sum += a[i]; if( sum > Maxsum ) { Maxsum = sum; inds = t; inde = i; } } if( Maxsum < 0 ) { printf("0 %d %d\n", a[0], a[n-1]); } else { printf("%d %d %d\n", Maxsum, a[inds], a[inde]); } } } int main(){ input(); return 0; }
加一个一模一样的题~~就只是不会出现全为负的情况~
http://acm.hdu.edu.cn/showproblem.php?pid=1003
//Asimple //#include <bits/stdc++.h> #include <iostream> #include <sstream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <cctype> #include <cstdlib> #include <stack> #include <cmath> #include <set> #include <map> #include <string> #include <queue> #include <limits.h> #include <time.h> #define INF 0xfffffff #define mod 1000000 #define swap(a,b,t) t = a, a = b, b = t #define CLS(a, v) memset(a, v, sizeof(a)) #define debug(a) cout << #a << " = " << a <<endl #define abs(x) x<0?-x:x #define srd(a) scanf("%d", &a) #define src(a) scanf("%c", &a) #define srs(a) scanf("%s", a) #define srdd(a,b) scanf("%d %d",&a, &b) #define srddd(a,b,c) scanf("%d %d %d",&a, &b, &c) #define prd(a) printf("%d\n", a) #define prdd(a,b) printf("%d %d\n",a, b) #define prs(a) printf("%s\n", a) #define prc(a) printf("%c", a) using namespace std; typedef long long ll; const int maxn = 100001; int n, m, num, T, k, len, ans, sum; int edx, edy, stx, sty; int a[maxn]; void input() { srd(T); for(int k=1; k<=T; k++) { srd(n); for(int i=1; i<=n; i++) { srd(a[i]); } int inds = 1; int inde = 1, t = 1; int Maxsum = -INF; int sum = 0; for(int i=1; i<=n; i++) { if( sum < 0 ) { sum = a[i]; t = i; } else sum += a[i]; if( sum > Maxsum ) { Maxsum = sum; inds = t; inde = i; } } printf("Case %d:\n", k); printf("%d %d %d\n", Maxsum, inds, inde); if( k < T ) { printf("\n"); } } } int main(){ input(); return 0; }
标签:deb map ddd sum 数据 rdd str limits amp
原文地址:http://www.cnblogs.com/Asimple/p/6229889.html