HDU_5504 GT and sequence
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
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
2
T
(test numbers).
For each test,in the first line there is a number N
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.
1
3
1 2 3
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的更多相关文章
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [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 ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- [LeetCode] Permutation Sequence 序列排序
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
随机推荐
- JAVA 解析、编辑nginx.conf
最近工程开发遇到一个需求:用Java去解析并编辑nginx.conf 在github上找到nginx-java-parser工具,项目地址:https://github.com/odiszapc/ng ...
- iView的使用【CDN向】
直接粗暴地上html代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- HTML基本功之文档结构
项目名 首页 命名为 index.html 样式文件夹 命名为 css /*用来放样式文件*/ base.css /*基本样式*/ index.css /*首页样式*/ global.css /* ...
- RSA加解密实现
RSA是由MIT的三位数学家R.L.Rivest,A.Shamir和L.Adleman[Rivest等1978, 1979]提出的一种用数论构造双钥的方法,被称为MIT体制,后来被广泛称之为RSA体制 ...
- 房上的猫:HTML5基础
一.W3C标准 1)W3C标准不是某一个标准,而是一系列的标准的集合,一个网页主要由三部分组成,即结构(Structure),表现(Presentation)和行为(Behavior) 2)不很严谨的 ...
- 房上的猫:if选择结构
一.基本if结构: 1.定义:if选择结构是根据条件判断之后再做处理的一种语法结构! 2.逻辑:首先对条件进行判断 >如果为真,则执行代码块 >如果为假,执行代码块后面的部分二.常用逻 ...
- IIFF(立即执行函数表达式)
立即执行函数表达式(Immediately-invoked function expression,IIFF) 在javascript(ES5)中,是没有块级作用域的概念的 for (var i = ...
- Linux(Cent OS7.2)下启动停止memcached方法及ps命令使用讲解
Linux下,以Cent OS7.2为例,安装memcached后的启动方法很简单,这里我们使用yum源安装. 首先查找yum源版本库的memchaced安装包, yum list | grep me ...
- c/c++ 贪吃蛇控制台版
贪吃蛇控制台版(操作系统win7 64位:编译环境gcc, vs2017通过,其它环境未测试 不保证一定通过) 运行效果: #include <iomanip> #include < ...
- Java学习笔记1(HelloWorld)
编写HelloWorld是一种仪式: 1.下载JDK,安装,注意路径中不要存在中文. 2.添加环境变量,加入bin目录 3.写一个文本,内容如下,后缀改成.java,注意文本的名称为HelloWorl ...