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. 遍历map的几种方式

    1,平时开发中对map的使用很多,然后发现了很多map可能存在的各种问题:如HashMap 需要放置 1024 个元素,由于没有设置容量初始大小,随着元素不断增加,容量 7 次被迫扩大,resize ...

  2. android 串口开发第一篇:搭建ndk开发环境以及第一个jni调用程序

    一:ndk环境搭建 1:开发环境 我使用的是android studio 2.3.3版本,搭建ndk开发环境比较简单,打开File----Settings----Appearance&Beha ...

  3. Ionic2 cordova angular2 打包到Android apk环境搭建

    一.前言 前段时间,公司有个APP项目需要支持不同平台,于是采用了Ionic2 + cordova + angular2,在搭建环境过程中遇到了不少问题,刚好最近有时间整理出来. 二.开发环境搭建 参 ...

  4. Python的HTTP服务实例

    1.前言 今天需要实现一个Pyhton的http服务,与Web的JS进行交换. 2.实例代码 支持HEAD.GET.POST方法,将参数转换为JSON格式,返回结果以JSON字符串返回. import ...

  5. MySQL Group Replication 动态添加成员节点

    前提: MySQL GR 3节点(node1.node2.node3)部署成功,模式定为多主模式,单主模式也是一样的处理. 在线修改已有GR节点配置 分别登陆node1.node2.node3,执行以 ...

  6. Python学习(三):迭代器、生成器、装饰器、递归、算法、正则

    1.迭代器 迭代器是访问集合的一种方式,迭代对象从集合的第一个元素开始访问,直到元素被访问结束,迭代器只能往前不能后退,最大的优点是不要求事先准备好整个迭代过程中的元素,这个特点使得它特别适合用于遍历 ...

  7. python3.5 + PyQt5 +Eric6 实现的一个计算器

    目前可以实现简单的计算.计算前请重置,设计的时候默认数字是0,学了半天就做出来个这么个结果,bug不少. python3.5 + PyQt5 +Eric6 在windows7 32位系统可以完美运行 ...

  8. Oracle学习笔记_07_模糊查询

    附录:参考资料 1.Oracle sql语言模糊查询--like后面的通配符 2.oracle sql语言模糊查询--通配符like的使用教程

  9. 【转】nginx提示:500 Internal Server Error错误的解决方法

    本文转自:http://www.jb51.net/article/35675.htm 现在越来越多的站点开始用 Nginx ,("engine x") 是一个高性能的 HTTP 和 ...

  10. vue监听scroll使用报错的解决办法

    错误说明:在切换路由以后,依旧在其他页面触发了scroll有关的函数, 错误原因:在spa项目中,window对象是不变的,所以每次使用后需要销毁. 解决办法:vue的生命周期destroyed中销毁 ...