UVA 11059 Maximum Product (enumeration start+end)

Source: Internet
Author: User

Main topic:

That is to give you n numbers, and then to find out the maximum and the continuous sequence. If ANS is negative, the output is 0, or the ANS is output.

Problem Solving Ideas:

In fact, we just need to enumerate the starting point and the end point, and then consider all the circumstances, a bit similar to solving the problem of maximum continuity.

The only difference is to initialize T = 1, t*=a[j] every time. Note Long long. Because there are up to 18 numbers, and each number

The maximum value is 10, then their product will not exceed 10^18.

Code:

# include<cstdio># include<iostream># include<algorithm># include<functional># include<cstring># include<string># include<cstdlib># include<iomanip># include<numeric># include<cctype># include<cmath># include<ctime># include<queue># include<stack># include<list># include<Set># include<map>using namespacestd;Const DoublePi=4.0*atan (1.0); typedefLong Longll;typedef unsignedLong Longull;# define INF999999999# define MAX atintA[max];intN;intMainvoid){    intIcase =1;  while(cin>>N) { for(inti =1; I <= n;i++) {cin>>A[i]; } LL ans=0;  for(inti =1; I <= n;i++) {LL T=1; //ans = max (ans,t);         for(intj = I;j <= n;j++) {T*=A[j]; Ans=Max (ans,t); }} printf ("Case #%d:the Maximum product is%lld.\n\n", icase++, ans); }    return 0;}
View Code

UVA 11059 Maximum Product (enumeration start+end)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.