题目链接: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 263−1

.

 
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.

1≤T≤1000

1≤N≤62

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\n");
continue;
}
if(m==1)//只输入一个数
{
printf("%lld\n",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\n");
continue;
}
printf("%lld\n",sum1*sum2);
}
return 0;
}

  

hdu 5504 GT and sequence的更多相关文章

  1. HDU 5504 GT and sequence 模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5504 思路:模拟 代码: #include<stdio.h>//------杭电5504 ...

  2. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  3. 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence

    // 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...

  4. hdu 4893 Wow! Such Sequence!(线段树)

    题目链接:hdu 4983 Wow! Such Sequence! 题目大意:就是三种操作 1 k d, 改动k的为值添加d 2 l r, 查询l到r的区间和 3 l r. 间l到r区间上的所以数变成 ...

  5. Hdu 5496 Beauty of Sequence (组合数)

    题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...

  6. Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)

    Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...

  7. HDU 5063 Operation the Sequence(暴力)

    HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...

  8. HDU 5288 OO’s Sequence [数学]

     HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...

  9. HDU - 1711 A - Number Sequence(kmp

    HDU - 1711 A - Number Sequence   Given two sequences of numbers : a[1], a[2], ...... , a[N], and b[1 ...

随机推荐

  1. 【BZOJ 3190】 3190: [JLOI2013]赛车 (半平面交)

    3190: [JLOI2013]赛车 Description 这里有一辆赛车比赛正在进行,赛场上一共有N辆车,分别称为个g1,g2--gn.赛道是一条无限长的直线.最初,gi位于距离起跑线前进ki的位 ...

  2. Get请求携带数据量的各种限制及解决办法、Post请求说明

    1.   Get请求携带数据量的各种限制及解决办法 Http Get方法提交的数据大小长度并没有限制,HTTP协议规范没有对URL长度进行限制.这个限制是特定的浏览器及服务器对它的限制. 到新公司处理 ...

  3. objective-C 自定义对象归档的实现

    自定义对象要实现归档必须实现NSCoding协议 NSCoding协议有两个方法,encodeWithCoder方法对对象的属性数据做编码处理,initWithCoder解码归档数据来初始化对象. # ...

  4. Rabbitmq中rabbitmqctl的常用命令

    学习rabbitmq,原理之后第一个要掌握的就是rabbitmqctl这个命令的用法了,rabbitmq的管理功能最全的就是rabbitmqctl命令了,当然还有HTTP API和UI两种管理手段. ...

  5. VPN column: PPTP(1)--connecting process

    hu_hit原创,如需转载请注明出处.Thanks. 在未来几天会总结一下PPTP的工作过程,分为以下3篇讲述. 1. PPTP连接过程: 2. PPTP协议解析: 3. PPTP的路由. 由于我是工 ...

  6. poj 3267 The Cow Lexicon(dp)

    题目:http://poj.org/problem?id=3267 题意:给定一个字符串,又给n个单词,求最少删除字符串里几个字母,能匹配到n个单词里 #include <iostream> ...

  7. poj2182

    首先容易知道,最后一个数是最容易确定的,于是从后往前确定 对于位置j,它的数就是1~n中剩余数的第a[j]+1小的数 这当然可以用平衡数做,复杂度为O(nlogn) 有没有更简洁得算法?树状数组+二分 ...

  8. Tomcat 配置问题总结

    本人是一个前端屌丝儿,最近没事研究了一下tomcat的部署问题,一下列几个实用的小技能(直接上干货了,不赘述): 1,路径引用部署 在tomcat目录下的conf/Catalina/localhost ...

  9. 「拒絕存取路徑 'C:\Users\xxx\AppData\Local\Temp\Temporary ASP.NET Files\apname\3a1b3704\f7fc6d0c\App_Code.l8ieogii.0.cs」的錯誤!

    修改web.config中的system.web->compilation tag中,多加入tempDirectory="可存取的目錄"   <system.web&g ...

  10. Arch 常用工具

    一.网络浏览 pacman -S firefox firefox-i18n注:该命令中的前者为 Firefox 主程序,后者为语言包.pacman -S opera 二.图像编辑 pacman -S ...