题目链接: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. if语句写在while语句外面效率更高

    为了排除某些特殊的文件后缀名,一开始我自然而然的这样写,判断每一个文件的后缀名: // 去除后缀名 foreach (const QString &strKey, local_map.keys ...

  2. Java API ——Arrays类

    1.Arrays类概述 · 针对数组进行操作的工具类. · 提供了排序,查找等功能. 2.成员方法 · public static String toString(int[] a):in[] a可以改 ...

  3. P99、面试题13:在o(1)时间删除链表结点

    题目:给定单向链表的头指针和一个结点指针,定义一个函数在o(1)时间删除该结点.链表结点与函数的定义如下:struct ListNode{       int m_nValue;       List ...

  4. 你想建设一个能承受500万PV/每天的网站吗?

    (如果感觉有帮助,请帮忙点推荐,添加关注,谢谢!你的支持是我不断更新文章的动力.本博客会逐步推出一系列的关于大型网站架构.分布式应用.设计模式.架构模式等方面的系列文章) 你想建设一个能承受500万P ...

  5. android 电容屏(一):电容屏基本原理篇

    平台信息: 内核:linux3.4.39系统:android4.4 平台:S5P4418(cortex a9) 作者:瘋耔(欢迎转载,请注明作者) 欢迎指正错误,共同学习.共同进步!! 关注博主新浪博 ...

  6. jquery获取元素索引值index()方法

    jquery的index()方法 搜索匹配的元素,并返回相应元素的索引值,从0开始计数. 如果不给 .index() 方法传递参数,那么返回值就是这个jQuery对象集合中第一个元素相对于其同辈元素的 ...

  7. 【HDOJ】4652 Dice

    1. 题目描述对于m面的骰子.有两种查询,查询0表示求最后n次摇骰子点数相同的期望:查询1表示最后n次摇骰子点数均不相同的期望. 2. 基本思路由期望DP推导,求得最终表达式.(1) 查询0    不 ...

  8. Android开发之全局获取Context的技巧

    转自<第一行代码-Android>进阶篇 这本书对于入门来说确实很棒,很简单明了的介绍了Android开发中涉及到的方方面面,对我的帮助很大,同时记录一些该书中一些对我以后开发有用的东西, ...

  9. Java web 项目 tomcat部署方式.

    本地做Java Web项目的时候常常会用到tomcat部署测试的问题, 这里介绍项目的部署方法: 1,配置文件的形式: 例如: 你的项目目录为:f:\workspaces\MyProject,此时使用 ...

  10. Excel 内容粘贴到DataGridView, DataGridView 粘贴到 Excel

    void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Ke ...