麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

1003.Max Sum

2019-11-06 07:19:01
字體:
來源:轉載
供稿:網友
PRoblem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.Sample Input25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5Sample OutputCase 1:14 1 4Case 2:7 1 6

求每一位置的最大連續和,取最大的就好了

#include<iostream>using namespace std;int main(){ int N; cin >> N; for (int t = 1;t <= N;t++) { if (t != 1) putchar('/n'); printf("Case %d:/n", t); int M; cin >> M; int s_min=0, s_v=1; int s_max=-1001, s_h,s_l; int sum = 0; for (int i = 1;i <= M;i++) { int te;cin >> te; sum += te; if (sum - s_min >= s_max) { s_max = sum - s_min;s_h = i;s_l = s_v; } if (sum < s_min) { s_min = sum;s_v = i + 1; } } printf("%d %d %d/n", s_max, s_l, s_h); }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄色毛片免费看 | 精品国产乱码久久久久久丨区2区 | 日本a∨精品中文字幕在线 欧美1—12sexvideos | 91精品国产99久久久久久 | 一级做a爱片性色毛片 | 成年免费大片黄在线观看岛国 | 午夜人体| 久久爽精品区穿丝袜 | 7777久久香蕉成人影院 | 成人电影毛片 | 黄网站色成年大片免费高 | 日韩视频区 | 77成人影院 | 免费午夜视频在线观看 | 久久久久久久亚洲精品 | 黄污在线观看 | 草草视频免费观看 | 精品三级内地国产在线观看 | 欧美精品一区二区三区在线播放 | 成人男男视频拍拍拍在线观看 | 91久久久久久久一区二区 | 国产午夜精品久久久久 | 夜夜看| 久久久成人一区二区免费影院 | 免费看成人av | 中文字幕免费一区 | 国产精品久久久久久久午夜片 | 27xxoo无遮挡动态视频 | 欧美1区2区在线观看 | 国产日产精品一区二区三区四区 | 国产一区二区免费在线观看视频 | 日韩激情| 免费a级黄色片 | 日本欧美一区二区三区在线观看 | 国产成人强伦免费视频网站 | 国产免费区 | 成人在线观看一区二区三区 | 国产盼盼私拍福利视频99 | 黄色特级视频 | 成人性生活视频在线观看 | 国产精品美女久久久免费 |