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. Java并发编程之ThreadLocal源码分析

    ## 1 一句话概括ThreadLocal<font face="微软雅黑" size=4>  什么是ThreadLocal?顾名思义:线程本地变量,它为每个使用该对象 ...

  2. ArcGIS API for JavaScript 4.2学习笔记[31] (补充学习)Task类

    Task这个东西很有用,是AJS中用于解决各种乱七八糟任务的一个类.它有很多子类,有用于空间分析的,有用于空间查询的,等等. 这篇作为补充学习的第一篇,也是进阶学习的第一篇,我就改个写法. 我将使用思 ...

  3. 公牛与状压dp

    T1 疾病管理 裸得不能再裸的状压dp 不过数据范围骗人 考试时k==0的点没过 我也很无奈呀qwq #include<iostream> #include<cstdio> # ...

  4. c#的关键字

    abstract as base bool break byte case catch char checked decimal default delegate continue double do ...

  5. python学习中的一些“坑”

    一.交互列表元素时,需要注意的坑. 例如: array=[4,5,9,8,10,8,4,0,3,4]  最大的值与第一个元素交换,最小的值与最后一个元素交换 # -*- coding: UTF-8 - ...

  6. sql存储过程中使用 output

    1.sql存储过程中使用 output CREATE PROCEDURE [dbo].[P_Max] @a int, -- 输入 @b int, -- 输入 @Returnc int output - ...

  7. Python 阿里大于发送手机验证码

    1.安装阿里大于的包 pip install top 2.事例脚本 # -*- coding: utf-8 -*- import top.api appkey = '2353xxxx' secret ...

  8. 前端学习_04_font-awesome字体图标

    使用font-awesome字体图标库 font-awesome是一个比较大的矢量图标库,包含大部分IT类公司logo和常用的一些小图标,通过使用font-awesome提供的css样式集,可以在网页 ...

  9. angular4.0使用JSONP数据请求

    ng4中有很多获取数据的API,为了满足跨域的需求,我选择JSONP模块: 应该有很多小伙伴遇到这个报错吧 injected script did not invoke callback: 下面我写个 ...

  10. Spark源码分析 之 Driver和Excutor是怎么跑起来的?(2.2.0版本)

    今天抽空回顾了一下Spark相关的源码,本来想要了解一下Block的管理机制,但是看着看着就回到了SparkContext的创建与使用.正好之前没有正式的整理过这部分的内容,这次就顺带着回顾一下. S ...