hdoj5501GT and sequence
2016-01-25 00:27
357 查看
GT and sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2444 Accepted Submission(s): 556
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
Source
BestCoder Round #60
#include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn=10010; long long num[70]; int main() { int t,i,j,k,n,m; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=0;i<n;++i){ scanf("%lld",&num[i]); } sort(num,num+n); long long ans1=1,ans2=1,pos,cnt=0; bool flag=false; for(i=n-1;i>=0;--i){ if(num[i])flag=true; if(num[i]>0)ans1*=num[i]; else if(num[i]<0)ans2*=num[i]; if(num[i]<0)cnt++; if(i!=n-1&&num[i]<0&&num[i+1]>=0)pos=i; } if(num[n-1]<0)pos=n-1; if(!flag){ printf("0\n"); } else if(ans2>0){ printf("%lld\n",ans1*ans2); } else { if(cnt==1){ if(num[n-1]==0){ printf("0\n"); } else if(num[n-1]<0){ printf("%lld\n",num[n-1]); } else printf("%lld\n",ans1); } else printf("%lld\n",ans1*ans2/num[pos]); } } return 0; }
相关文章推荐
- Varnish Install And Configure
- Insert Date and Time into Access
- asp的SQL语句中and和or同时使用的注意事项
- 拖动Html元素集合 Drag and Drop any item
- 学习drag and drop js实现代码经典之作
- And,Where使用提示以及用+进行左关联的提示及注意事项
- Android开发adb.exe' and can be executed.错误解决方法
- Table ‘xxx’ is marked as crashed and should be repaired 错误解决方法参考
- drag-and-drop实现图片浏览器预览
- python关键字and和or用法实例
- Python and、or以及and-or语法总结
- Python中AND、OR的一个使用小技巧
- Nginx中IF、AND、OR语句用法实例
- 负载均衡及会话保存(Ofbiz框架)
- Multithreading and Synchronization
- Due Care and Due Diligence
- DAS, NAS, and SAN
- Security Descriptors and Access Control Lists Tools and Settings
- 常用的Net Command
- makefile.in and makefile.am