Question link: http://uva.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 448
Pay attention to the following situations for this question. For details, refer to the code.
If more than one segment is maximally nice, choose the one with the longest cycle ride (largest j-i).To break ties in longest maximal segments,choose the segment that begins with the earliest stop(lowest i)
Typical maximum child segments and problems.
# Include <iostream> using namespace STD; int main () {int testnumber; // number of tests CIN> testnumber; For (INT Index = 1; index <= testnumber; index ++) // cyclically test each group of data {int max = 0, sum = 0, tempnumber = 0; int tempstart = 0; int start = 0, end = 0; int number; CIN> Number; For (INT I = 0; I <number-1; I ++) {CIN> tempnumber; sum + = tempnumber; if (sum <0) // if it is less than 0, the previous value is temporarily abandoned and the next value is used as the starting point {tempstart = I + 1; sum = 0 ;} if (sum> max | (sum = max & START = tempstart) // {max = sum; Start = tempstart is updated only when the value is greater than the maximum value; end = I ;}}if (max = 0) cout <"Route" <index <"has no nice parts" <Endl; else cout <"the nicest part of Route" <index <"is between stops" <start + 1 <"and" <End + 2 <Endl;} return 0 ;}