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;
    }
    

      

  • 相关阅读:
    DataSet & DataTable &DataRow 深入浅出(转)
    使用三种方式搭建IIS web 网站
    淘宝系App图片为什么在北京电信网络加载这么慢?
    面向新手的Web服务器搭建(一)——IIS的搭建
    Ajax请求中的async:false/true的作用
    .net SerialPort
    .net常用属性
    Active Directory 常用属性
    .net加密
    MongoDb
  • 原文地址:https://www.cnblogs.com/tonghao/p/5020719.html
Copyright © 2011-2022 走看看