Problem 1478 环形整数串 from http://acm.fzu.edu.cn/problem.php?pid=1478
来源:互联网 发布:查士丁尼瘟疫 知乎 编辑:程序博客网 时间:2024/05/01 20:29
Problem Description
你知道最大和子串问题么? 就是给你一个整数串,要你求出其中的一个连续子串,要求其和最大。
比如: 串是 -2 2 0 1 -48 1,显然其最大和连续子串是2 0 1,其和是3。
现的问题是如果求环形整数串的最大连续和子串呢?
请编写一个程序解决这个问题。
Input
本题有多组输入数据,你必须处理到EOF为止
每组数据的第一行有一个整数n, (1<=n<=1000000).第2行有n个整数,每个整数都在[-100,100]的范围内
Output
每组数据输出一个整数,表示环形整数串最大连续子串和。
Sample Input
6-2 3 0 1 -48 8021 3
Sample Output
824
Source
FOJ月赛-2007年3月需要注意当min=sum时,sum-min是没有东西的。
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- using namespace std;
- int main(){
- //freopen("in.txt", "r", stdin);
- long long sum;
- long long max;
- long long smax;
- long long smin;
- long long min;
- int num;
- int n;
- while(cin>>n){
- scanf("%d", &num);
- smax = num;
- max = num;
- smin = num;
- min = num;
- sum = num;
- for(int i=1;i<n;++i){
- scanf("%d", &num);
- sum += num;
- smax = smax>0?smax+num:num;
- smin = smin<0?smin+num:num;
- if(smax>max){
- max = smax;
- }
- if(smin<min)
- min = smin;
- }
- if(sum-min>max && sum!=min)
- cout<<sum-min<<endl;
- else
- cout<<max<<endl;
- }
- //fclose(stdin);
- return 0;
- }
- Problem 1478 环形整数串 from http://acm.fzu.edu.cn/problem.php?pid=1478
- Problem 1057 ab from http://acm.fzu.edu.cn/problem.php?pid=1057
- Problem 1453 Bignum Arithmetic from http://acm.fzu.edu.cn/problem.php?pid=1453
- Problem 1410 变位词 from http://acm.fzu.edu.cn/problem.php?pid=1410
- Problem 1207 半数集问题 from http://acm.fzu.edu.cn/problem.php?pid=1207
- Problem 1607 Greedy division from http://acm.fzu.edu.cn/problem.php?pid=1607
- Problem 1582 众数问题 from http://acm.fzu.edu.cn/problem.php?pid=1582
- Problem 1046 Tempter of the Bone, from http://acm.fzu.edu.cn/problem.php?pid=1046
- Problem 1202 信与信封问题 from http://acm.fzu.edu.cn/problem.php?pid=1202
- fzu 1402 中国剩余定理 http://acm.fzu.edu.cn/problem.php?pid=1402
- http://acm.fzu.edu.cn/problem.php?pid=1698 最大乘积
- http://acm.fzu.edu.cn/problem.php?pid=2113 数位DP
- 单调队列入门 foj 1894 http://acm.fzu.edu.cn/problem.php?pid=1894
- http://acm.uestc.edu.cn/problem.php?pid=1784&&
- http://acm.fzu.edu.cn/problem.php?pid=1564 C(n,k)和素数P的问题
- http://acm.uestc.edu.cn/problem.php?pid=1480&cid=164
- A + B Problem II &&http://acm.hdu.edu.cn/showproblem.php?pid=1002
- http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=301 (矩阵的用法)
- http://ac.jobdu.com/problem.php?pid=1011
- http://ac.jobdu.com/problem.php?pid=1010
- 餐饮经营思考(一)——利润&成本
- Problem 1607 Greedy division from http://acm.fzu.edu.cn/problem.php?pid=1607
- Problem 1582 众数问题 from http://acm.fzu.edu.cn/problem.php?pid=1582
- Problem 1478 环形整数串 from http://acm.fzu.edu.cn/problem.php?pid=1478
- Visual CertExam Suite v3 0 1 Cracked-BLiZZARD
- ZOJ Problem Set - 3661 Palindromic Substring
- JPEG图片存储格式及原理
- JS + CSS 超漂亮切换效果
- MyBatis传参方式和批量操作总结
- 光标控制器
- 通过libvirt和convirt来管理KVM虚拟机
- 开发者的发展 一个 Python 程序员的进化