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 ...
随机推荐
- java thread类和runable
java thread 类其实和其他类是一样的.有自己的属性和方法.以及有一个重写的run方法 不同的是:必须重写run()方法. run()方法是线程thread启动后cpu调用运行的程序代码. r ...
- size_t和ssize_t
Ssize_t 与size_t 跟踪linux源码得到以下宏: #ifndef _SIZE_T #define _SIZE_T typedef __kernel_size_t size ...
- PHP实现浏览历史记录
http://www.3a88.com/service/206.html http://www.1360.cc/ZhanChangJiaoCheng/6831.html http://www.osch ...
- 获取View的高度宽度,屏幕参数,状态栏高度
基础 各区域示例,注意绿色,紫色,橙色区域 注意: 在onCreate只是对象的初始创建过程,这时并没有draw,这时view.getHeight返回0,可在onStart里用getHeight等. ...
- bash把所有屏幕输出重定向到文件并保持屏幕输出的方法
输出到文件log中,并在屏幕上显示:#ls >&1 | tee log 追加输出到文件log中,并在屏幕上显示:#ls >&1 | tee -a log
- MQ-传输方式Topic和Queue的对比
Jms规范里的两种message传输方式Topic和Queue,两者的对比如下表(): Topic Queue 概要 Publish Subscribe messaging 发布订阅消息 Poi ...
- 第二部分 overlay 架构初探
1 overlay可能支持的颜色格式/* possible overlay formats可能支持的颜色格式 */enum { OVERLAY_FORMAT_RGBA_8888 = HAL ...
- UVa 1471 (LIS变形) Defense Lines
题意: 给出一个序列,删掉它的一个连续子序列(该子序列可以为空),使得剩下的序列有最长的连续严格递增子序列. 分析: 这个可以看作lrj的<训练指南>P62中讲到的LIS的O(nlogn) ...
- Spring depends-on介绍
<!-- redis配置 --> <bean id="jedisPoolConfig" class="redis.clients.jedis.Jedis ...
- iOS开发之UILabel
UILabel是iOS开发中常用的一个组件,主要用来显示内容. UILabel的主要使用如下: /*尺寸*/ CGRect labelRect = CGRectMake(100, 100, 80, 4 ...