zoukankan      html  css  js  c++  java
  • hdu 5504 GT and sequence

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5504

    GT and sequence

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 2223    Accepted Submission(s): 510


    Problem Description
    You are 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 will not bigger than 2631 .
     
    Input
    In 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 are N numbers.

    1T1000
    1N62

    You'd better print the enter in the last line when you hack others.

    You'd better not print space in the last of each line when you hack others.
     
    Output
    For each test case,output the answer.
     
    Sample Input
    1
    3
    1 2 3
     
    Sample Output
    6
     
    #include<stdio.h>
    #include<string.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<algorithm>
    #define LL long long
    #define MAX 1100
    using namespace std;
    int main()
    {
    	LL t,n,m,j,i,k;
    	LL x,a1,b1,c;
        LL s[1100],a[MAX],b[MAX];
    	scanf("%lld",&t);
    	while(t--)
    	{
    		scanf("%lld",&m);
    		a1=b1=c=0;
    		for(i=0;i<m;i++)
    		{
    			scanf("%lld",&s[i]);
    			if(s[i]<0)
    			    a[a1++]=s[i];
    			else if(s[i]>0)
    			    b[b1++]=s[i];
    			else
    			    c++;
    		}
    		LL sum1=1;
    		LL sum2=1; 
    		if(c==m)//只输入0 
    		{
    			printf("0
    ");
    			continue;
    		}
    		if(m==1)//只输入一个数 
    		{
    			printf("%lld
    ",s[0]);
    			continue;
    		}
    		sort(a,a+a1);
    		sort(b,b+b1);
    		for(i=0;i<b1;i++)//正数和 
    		    sum1*=b[i];
    		    
    	    if(a1%2==0)//偶数个负数的话,所有负数乘 
    	    {
    	    	for(i=0;i<a1;i++)
    		        sum2*=a[i];
    	    }
    	    else //奇数个负数,最大的负数不乘 
    	    for(i=0;i<a1-1;i++)
    	        sum2*=a[i];
    	        
    		if(c!=0&&b1==0&&a1==1)//输入1个负数和0 
    		{
    			printf("0
    ");
    			continue;
    		}
    		printf("%lld
    ",sum1*sum2);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    CocoaPods初试用(1)
    iOS界面调试利器DCIntrospect
    iOS开发中sqlite3基本应用
    禁用iOS7系统自带的pop手势
    iOS7开发~Xcode5制作framework
    完美兼容iOS7自定义的AlertView
    iOS float类型比较大小
    iOS开发应用更新时,须注意事项
    Tesseract 文字识别 运用于ios7 xcode5 任意工程
    oc学习之路----内存管理
  • 原文地址:https://www.cnblogs.com/tonghao/p/5020719.html
Copyright © 2011-2022 走看看