hdu5504 GT and sequence (Bestcoder Round #60)

Source: Internet
Author: User

Tags: water BC

GT and SequenceTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 334 Accepted Submission (s): 85

Problem descriptionyou is given a sequence of N Integers.

You should choose some numbers (at least one), and make the product of them as big as possible.

It guaranteed that **the absolute value of** any product of the numbers you choose in the initial sequence would not bigger than < Span style= "Position:absolute; Top:-4em; Left:0em ">2 63 ? 1 .
Inputin The first line there is a number T (Test numbers).

For each test,in the first line there is a number N , and in the next line there is N Numbers.


You ' d better print the ' Enter ' and ' last line ' hack others.

You ' d better not print space in the last of all line when you hack others.
Outputfor each test case,output the answer.
Sample Input
131 2 3

Sample Output

Sourcebestcoder Round #60
Test instructions: Given a sequence, the maximum value of the product is selected from any number. Analysis: This problem too many pits, have to slowly discover.
#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue > #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> Using namespace Std;const double eps = 1e-6;const double pi = ACOs ( -1.0); const int INF = 0x3f3f3f3f;const int MOD = 100000    0007; #define LL Long Long#define CL (a) memset (A,0,sizeof (a)) int main () {int T;    ll N,x,sum;    cin>>t;        while (t--) {cin>>n;        sum = 0;        int k=0,re=0;        LL maxx =-inf;            for (int i=0; i<n; i++) {cin>>x;            if (x = = 0) {re++; continue;}                if (x < 0) {k++;            Maxx = Max (Maxx, X);            } if (i = = re) sum = x;        else sum *= x;        }//cout<<re<< "" <<k<<endl; if (k%2&&n!=1&&! (        k==1&&re+k==n)) Sum/= Maxx; if (RE&GT;0&AMP;&AMP; (sum<0| |                n==1)) sum = 0;    cout<<sum<<endl; } return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

hdu5504 GT and sequence (Bestcoder Round #60)

Related Article

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.

Tags Index: