GT and sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1392    Accepted Submission(s): 322

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
水题一枚!可是坑了我两三次,结果没注意输入的数可以是long long 型wa了好几次~~
//题意:给你若干个整数,让你挑选若干数字使得其乘积最大
//算法分析:将这些数字都进行分类,正数、负数、零分别放在不同的一个数组中,然后再进行讨论!讨论负数时候,若为奇数个,去掉最大的那个,留下的相乘即可!偶数个直接相乘 #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <stack>
using namespace std; typedef long long int LL ; int main() {
int t;
cin >> t;
while (t --) {
int n;
cin >> n;
LL a[100];
LL b[100], c[100];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
int num1 = 0, num2 = 0;
int flag = 0;
for (int i = 0; i<n; i++) {
cin >> a[i];
if (a[i] > 0)
b[num1++] = a[i];
else if (a[i] < 0)
c[num2++] = a[i];
else
flag ++ ;
}
sort(c, c+num2);
LL res = 1;
if (num1 == 0) {
if (num2 == 0)
cout << 0<< endl;
else if(num2 == 1) {
if (flag == 0)
cout << c[0] << endl;
else
cout << 0<< endl;
}
else {
if (num2 %2 == 0) {
for (int i = 0; i<num2; i++)
res *= c[i];
}
else {
for (int i = 0; i<num2-1; i++)
res *= c[i];
}
cout << res << endl;
}
}
else {
for (int i = 0; i<num1; i++)
res *= b[i];
if (num2 %2 == 0) {
for (int i = 0; i<num2; i++)
res *= c[i];
}
else {
for (int i = 0; i<num2-1; i++)
res *= c[i];
}
cout << res << endl;
}
} return 0 ;
}

有坑跳才会进步!

HDU_5504 GT and sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. 关于js代码执行顺序

    上网查了一下关于这个方面的资料,大部分都是关于两个script标签中的js代码和变量以及函数提升方面的知识. 1.两个script标签 <script> alert("我是代码块 ...

  2. angularjs 字段排序 多字段排序

    我们用angularjs {{}},ng-model循环绑定数组或对象的内容的时候,有时候会用到排序,有时候可能会有多个字段排序 具体要用到过滤 数据的展现,可以通过ng-repeat实现.当网页解析 ...

  3. C语言--解引用

    昨天,在<C和指针>上面看到"解引用"这个名词,就好奇的去查了查. (下面是一个大一渣渣的理解,请各位朋友海涵,如果有漏洞或者补充希望前辈不吝指正.) 例: #incl ...

  4. linux 操作中命令备忘

    1 使用grep 查询关键内容 如果你想在当前目录下 查找"hello,world!"字符串,可以这样: grep -rn "hello,world!" * * ...

  5. 快速恢复开发环境(系统还原后的思考,附上eclipse注释的xml配置文件)

    1.Eclipse/Myeclipse的工作空间,不能放在系统盘 除非你的项目都有实时的云同步或SVN等,才能放在系统固态盘,不然你享受快速启动项目的同时,也需要承担系统奔溃后找不回项目的风险: 公司 ...

  6. MySQL 数据类型和约束(外键是重点🙄)

    数据类型 1. 数字(默认都是由符号,宽度表示的是显示宽度,与存储无关).tinyint 括号里指定宽度 七位2进制数最大数就是2**7 -1=127 最小是-128 验证: create tabel ...

  7. 一秒搞定mysql的远程登录

    执行下面命令! mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypw' WITH GRANT OPTION ; ...

  8. QtCreator 断点不起作用

    使用QtCreator 调试程序时一直无法进入断点,断点根本不起作用. 解决方法: 打开.pro文件 将图中的release改为debug,再次调试运行就可以进入断点了.

  9. word在线问题

    1.js代码如下 var sdata = "";$(function(){ var pathdoc = path.split("."); var explore ...

  10. xssgame挑战wp

    前言 昨晚做了一些xss的题目,有点上瘾了,今天想着再找一些来做做. google了一下,发现了不少,找到这么一个. 地址: https://xss-game.appspot.com 这是一个国外的x ...