http://acm.hdu.edu.cn/showproblem.php?pid=4561
The maximum continuous product.
How the hell did the dog push the train of thought?
The idea is%&* () * (& )) *) *&) ...%......%** (* () () ()--+ (* * (... &*......%&* ... y%^&%%^*&& (&* (&* (*& () *& (**......&%......&
%&......%&......& (&......* ()) & (**&......%*&&* (--+--) & (**......&%......&......*&%¥s%^& $**&%%&^a *&^&*** (^u (*) () ^ (*&^&* () &^**&*$%YT^&^%& ^^ &%%^%&%^ &%&^
%&^& (^&& (*&_) (&^*^u&*&op) _ (+_{() *&*&%^&%$&^$^%$#%^&*^& )(**)_(_+................................................
You know ...
I will translate;
In fact, the idea is to find a breakpoint, breakpoint is 0, that is, the demarcation of 0, the number of the given string into the K-segment such as 2220-2-2-22022;
Can be divided into 222-2-2-22 223, because if the selection of 0 words is definitely 0, the title of the product is less than or equal to 0 results are 0, so with 0 demarcation.
So that is the number of 2 per paragraph, and 2 of the number, if the number of 2 in the paragraph is an even number, then the length of this paragraph is directly compared with Maxx, Update Maxx,
If it is an odd number, suppose that n is looped from the left side of the paragraph to the edge until it encounters the nth-2 jump, so the front is not an even number-2.
Then from the right end of the loop to the left side, until the nth-2 jump, compared to two times the size of the large is the continuous maximum product of this section.
Because to be continuous and only one more-2, so say maximum either left continuous, or right continuous.
The last Maxx is the biggest;
1#include <stdio.h>2#include <iostream>3#include <stdlib.h>4#include <string.h>5#include <math.h>6typedefstructpp7 {8 intx;9 inty;Ten intX1; One intY1; A } SS; - using namespacestd; - intMainvoid) the { - inta[10005]; -SS cou[10005]; - intn,i,j,k,p,q; +scanf"%d",&n); - for(i=1; i<=n; i++) + { Ascanf"%d",&k); at for(j=0; j<k; J + +) - { -scanf"%d",&a[j]); -cou[j].x=0; -cou[j].y=0; -cou[j].x1=0; incou[j].y1=0; - } to if(a[0]>0) + { -cou[0].x++; the } * Else if(a[0]<0) $ {Panax Notoginsengcou[0].y++; - } the intmaxx=0; + for(j=1; j<k; J + +)//2-2 More from breakpoint to this point (from left loop) A { the if(a[j]>0) + { -cou[j].x=cou[j-1].x+1; $cou[j].y=cou[j-1].y; $ } - Else if(a[j]<0) - { thecou[j].y=cou[j-1].y+1; -cou[j].x=cou[j-1].x;Wuyi } the - } Wu if(a[k-1]>0) - { Aboutcou[k-1].x1++; $ } - Else if(a[k-1]<0) - { -cou[k-1].y1++; A } + for(j=k-2; j>=0; j--)//2-2 More from breakpoint to this point (right loop) the { - if(a[j]>0) $ { thecou[j].x1=cou[j+1].x1+1; thecou[j].y1=cou[j+1].y1; the } the Else if(a[j]<0) - { incou[j].y1=cou[j+1].y1+1; thecou[j].x1=cou[j+1].x1; the } About the } the for(j=0; j<k; J + +) the { + if(cou[j].y%2==0) - { the if(maxx<cou[j].x+cou[j].y)Bayi { themaxx=cou[j].x+cou[j].y; the } - } - if(cou[j].y1%2==0) the { the if(maxx<cou[j].x1+cou[j].y1) the { themaxx=cou[j].x1+cou[j].y1; - } the } the } theprintf"Case #%d:%d\n", I,maxx);94 } the return 0; the}
hdu-4561 Continuous maximum product (water problem)