hdu 5504 GT and sequence
题目链接: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
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
.
(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.
#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的更多相关文章
- HDU 5504 GT and sequence 模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5504 思路:模拟 代码: #include<stdio.h>//------杭电5504 ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence
// 判断相同区间(lazy) 多校8 HDU 5828 Rikka with Sequence // 题意:三种操作,1增加值,2开根,3求和 // 思路:这题与HDU 4027 和HDU 5634 ...
- 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区间上的所以数变成 ...
- Hdu 5496 Beauty of Sequence (组合数)
题目链接: Hdu 5496 Beauty of Sequence 题目描述: 一个整数序列,除去连续的相同数字(保留一个)后,序列的和成为完美序列和.问:一个整数序列的所有子序列的完美序列和? 解题 ...
- Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) (C++,Java)
Hdu 5806 NanoApe Loves Sequence Ⅱ(双指针) Hdu 5806 题意:给出一个数组,求区间第k大的数大于等于m的区间个数 #include<queue> # ...
- HDU 5063 Operation the Sequence(暴力)
HDU 5063 Operation the Sequence 题目链接 把操作存下来.因为仅仅有50个操作,所以每次把操作逆回去执行一遍,就能求出在原来的数列中的位置.输出就可以 代码: #incl ...
- 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 ...
- 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 ...
随机推荐
- linux ubuntu关于U盘的安装 开机启动u盘的时候出现/casper/vmlinuz.efi: file not found
将u盘下的/casper/vmlinuz文件添加一个后缀.efi即可. 重启再装.
- MySQL 5.6 安装配置
mysql 5.6.17下载安装图解_百度经验 http://jingyan.baidu.com/article/4b07be3c67853c48b380f311.html windows 8 系统将 ...
- profile工具
gprof callgrind vtune(待使用) ----time命令(待学习) ps -u <username> -H -opid,cmd strace
- POJ2109——Power of Cryptography
Power of Cryptography DescriptionCurrent work in cryptography involves (among other things) large pr ...
- Android 应用开发性能优化完全分析
1 背景 其实有点不想写这篇文章的,但是又想写,有些矛盾.不想写的原因是随便上网一搜一堆关于性能的建议,感觉大家你一总结.我一总结的都说到了很多优化注意事项,但是看过这些文章后大多数存在一个问题就是只 ...
- c++ const 关键字 学习笔记
const简单介绍: 1不再使用c中的#define,c++默认不给const定义的变量分配内存,所以它默认的是仅本文件可以看到该变量(即internal linkage), const int bu ...
- 驱动之路-platform简例按键驱动☆☆☆
一 .重要知识点: ▉1.platform设备模型 从Linux 2.6起引入了一套新的驱动管理和注册机制,platform_device和platform_driver,Linux中大部分的设备驱动 ...
- 基于Android Studio搭建Android应用开发环境
备注:电脑是windows xp系统 1. 安装JDK和环境变量设置 JDK是java development kit,Java JDK下载地址 http://www.oracle.com/t ...
- s3c6410 开发板Linux系统支持 K9GAG08U0E的方法
由于NandFlash硬件升级比较快,公司去年一直在使用三星的K9GAG08U0D,现在MLC NandFlash 升级到了第二代,K9GAG08U0D 很快就会处在停产的状态,未雨绸缪,公司选型了K ...
- Linux下修改PATH的方法
Linux下修改PATH的方法 1.直接在命令行里敲 PATH=$PATH:/path1:/path2:/pathN用户登出之后PATH恢复原样. 只是临时起作用. 2.修改~目录下bash_prof ...