BestCoder Round #60 GT and sequence (排序)
来源:互联网 发布:淘宝网客户关系管理 编辑:程序博客网 时间:2024/06/08 10:06
GT and sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 219 Accepted Submission(s): 60
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 than263−1 .
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
Input
In the first line there is a number T (test numbers).
For each test,in the first line there is a numberN ,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.
For each test,in the first line there is a number
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
131 2 3
Sample Output
6
Source
BestCoder Round #60
Recommend
hujie | We have carefully selected several similar problems for you: 5508 5507 5506 5505 5503
解析:用flag记录有没有0,如果有0,在之后的结果中与 0 取一个最大值。
直接排序,对于a[i],如果a[i]>0,那么ans*=a[i];
如果a[i]==0,那么不作处理;
如果a[i]<0并且a[i+1]<0,那么ans*=a[i]*a[i+1],否则不作处理。
代码:
#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;const int maxn=62;LL a[maxn+10];int main(){ freopen("1.in","r",stdin); LL t,n,i,ans; bool flag; scanf("%I64dd",&t); while(t--) { scanf("%I64d",&n); for(i=1;i<=n;i++)scanf("%I64d",&a[i]); sort(a+1,a+n+1),flag=a[0]=0; for(i=1;i<=n;i++) { if(a[i]<0 && (i+1<=n && a[i+1]<0)) a[++a[0]]=a[i],a[++a[0]]=a[i+1],i++; if(a[i]>0)a[++a[0]]=a[i]; if(a[i]==0)flag=1;} if(a[0]==0) { if(flag)ans=0; else ans=a[1];} else for(ans=1,i=1;i<=a[0];i++)ans*=a[i]; printf("%I64d\n",ans);} return 0;}
0 0
- BestCoder Round #60 GT and sequence (排序)
- BestCoder Round #60 HDU5504 GT and sequence
- hdu5504 GT and sequence(BestCoder Round #60 )
- hdu 5504 GT and sequence【BestCoder Round #60 】
- BestCoder Round #60 GT and numbers (模拟)
- BestCoder Round #60 GT and set (dfs)
- hdu5505 GT and numbers(BestCoder Round #60)
- BestCoder Round #60 HDU5505 GT and numbers
- BestCoder Round #60 5505GT and numbers
- GT and numbers(BestCoder Round #60)1002
- HDU 5504 GT and sequence(排除陷阱就是正解)——BestCoder Round #60
- hdu 5505 GT and numbers【BestCoder Round #60】
- BestCoder Round #3 BestCoder Sequence
- [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
- hdu4908 & BestCoder Round #3 BestCoder Sequence(组合数学)
- BestCoder Round #11 (Div. 2) Argestes and Sequence (hdu 5057)
- hdu 5057 Argestes and Sequence(BestCoder Round #11)
- GT and sequence 5504GT and sequence
- Spring4.0 学习(五)web.xml中ContextLoaderListeners的运行过程
- Spring常用注解---IoC
- HTML学习笔记之超链接的使用
- Sublime Text2.0.2注册码
- Java 实现栈
- BestCoder Round #60 GT and sequence (排序)
- Android APK反编译就这么简单 详解(附图)
- Parameter index out of range (1 > number of parameters, which is 0)
- nginx学习链接
- cocos2d-x跨平台游戏开发视频教程(一)
- 面向 iOS 开发的十款 XCode 插件
- 洛谷P2361 yyy棋
- 正则表达式30分钟入门教程
- 对付拖延心理的方法