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
 

思路:
这题恶心我了一晚上,昨天实在是没做的出来,今天缓了一天,然后给A了
题目大意是让你找出所给的一串数字中能达到的最大乘积,有很多的细节需要考虑
关键是要想到0,想清楚哪几种情况会受到0存在的影响
只要有正数存在,不管负数和0存在与否,都不会影响按照“一般流程”下来的最后结果
正数不存在,那么又有两种小的分支:负数也不存在和负数存在个数的问题
(1)只有一个负数,这个时候还要考虑有没有0!!!
(2)没有负数,只有0,那结果就是0.
是的,只有这两种情况会受到0存在的影响,要单独拿出来处理,其他的情况走大流程就OK

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std; int main()
{
int T;
__int64 t;
scanf("%d",&T);
while(T--)
{
__int64 ans = ;
__int64 a[];
int n;
int q = ,f = ;
scanf("%d",&n);
for(int i = ;i <= n;i++) {
scanf("%I64d",&t);
if(t > ) ans *= t;
else if(t == ) f++;
else a[++q] = t;
}
//把0会造成影响的两种特殊情况拿出来处理一下
if(q+f == n) {
if(!q) {
printf("0\n");
continue;
}
if(q == ) {
if(!f) {printf("%I64d\n",a[]);continue;}
if(f) {printf("0\n");continue;}
}
}
//如果有正数存在
if(q% == ) {
for(int i = ;i <= q;i++)
ans *= a[i];
printf("%I64d\n",ans);
continue;
}
else {
sort(a+,a++q);
for(int i = ;i <= q-;i++)
ans *= a[i];
printf("%I64d\n",ans);
continue;
}
}
) return ;
}

HDU-5504(逻辑if-else大水题)的更多相关文章

  1. hdu 4548 美素数 超级大水题

    美素数 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submis ...

  2. BZOJ_1621_[Usaco2008_Open]_Roads_Around_The_Farm_分岔路口(模拟+大水题)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1621\(n\)头奶牛,刚开始在一起,每次分成\(x\)和\(x+m\)两部分,直到不能再分,问 ...

  3. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  4. HDU 2802 F(N)(简单题,找循环解)

    题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  5. 第三届山西省赛1004 一道大水题(scanf)

    一道大水题 时间限制: C/C++ 2000ms; Java 4000ms 内存限制: 65535KB 通过次数: 44 总提交次数: 1020 问题描述 Dr. Pan作为上兰帝国ACM的总负责人, ...

  6. PAT甲题题解-1101. Quick Sort (25)-大水题

    快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着 ...

  7. PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)

    如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...

  8. 【数据结构】 最小生成树(四)——利用kruskal算法搞定例题×3+变形+一道大水题

    在这一专辑(最小生成树)中的上一期讲到了prim算法,但是prim算法比较难懂,为了避免看不懂,就先用kruskal算法写题吧,下面将会将三道例题,加一道变形,以及一道大水题,水到不用高级数据结构,建 ...

  9. Wannafly挑战赛21:C - 大水题

    链接:Wannafly挑战赛21:C - 大水题 题意: 现在给你N个正整数ai,每个数给出一“好数程度” gi(数值相同但位置不同的数之间可能有不同的好数程度).对于在 i 位置的数,如果有一在j位 ...

  10. 大水题(water)

    题目描述dzy 定义一个 $n^2$ 位的数的生成矩阵 $A$ 为一个大小为 $n \times n$ 且 Aij 为这个数的第 $i \times n+j-n$ 位的矩阵.现在 dzy 有一个数 $ ...

随机推荐

  1. 网页JavaScript4

    表单验证:一.非空验证:1.内容是不是空的.判断值的长度是不是0.length属性.压缩空格的函数. 2.内容是不是改变了. 二.对比验证:1.验证两个控件值的关系(相同,大小) 2.验证控件的值与某 ...

  2. Java Criteria表关联查询(两个表未定义关联关系)

    Criteria criteria = this.getSession().createCriteria(Competition.class, "b"); DetachedCrit ...

  3. Android开发手记(10) 下拉菜单Spinner

    1.自定义Spinner 首先,定义Spinner要显示的项目列表/res/values/arrays.xml <?xml version="1.0" encoding=&q ...

  4. 安全管理:IE6安全隐患重重 为何不离不弃

    安全服务商Zscaler的报告称,尽管微软IE6曾遭受一系列强势攻击并且新出的IE版本有更强的安全性能,但IE6依然受到各企业的热捧. 尽管微软一直敦促用户部署浏览器更新(截止2010年八月就将满九年 ...

  5. DWZ简介及其使用

    来源:http://blog.csdn.net/t123012009065/article/details/8286826 DWZ简介:   DWZ富客户端框架(jQuery RIA framewor ...

  6. apache_fileupload实现文件上传_上传多个文件

    1.导包 核心类: DiskFileItemFactory – 设置磁盘空间,保存临时文件.只是一个具类. ServletFileUpload  - 文件上传的核心类,此类接收request,并解析r ...

  7. JAVA-6-简单的模拟ATM使用

    public static void main(String[] args) { in = new Scanner(System.in); int count = 1; int pwd = 11111 ...

  8. 趣味PAT--循环-19. 币值转换(20)

    One visible minute on the stage is attributed to ten years of invisible practice off the stage. &quo ...

  9. spark 环境变量系列配置

    1. hadoop core-site.xml配置

  10. 正则表达式中/g的含义

    关于正则表达式 g,m 参数的总结,为了回答“正则表达式(/[^0-9]/g,'')中的"/g"是什么意思?”   为了解答“正则表达式(/[^0-9]/g,'')中的" ...