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

      

  • 相关阅读:
    C语言字符串读入函数笔记
    济大路痴
    Super Jumping! Jumping! Jumping!
    SpringMVC中静态资源的处理
    SpringMVC的拦截器讲解
    九、Spring中使用@Value和@PropertySource为属性赋值
    spring中最重要的一些Aware接口
    八、spring生命周期之BeanPostProcessor
    七、spring生命周期之初始化和销毁方法
    六、spring之通过FactoryBean为ioc容器中添加组件
  • 原文地址:https://www.cnblogs.com/tonghao/p/5020719.html
Copyright © 2011-2022 走看看