HDU GT and sequence (数的乘积最大)
来源:互联网 发布:ubuntu删除桌面文件夹 编辑:程序博客网 时间:2024/06/16 20:21
问题描述
给出N个整数。你要选择至少一个数,使得你选的数的乘积最大。保证任意选一些数相乘的绝对值都不会大于263−1。
输入描述
第一行读入一个数T表示数据组数。对于每组数据:第一行是一个数N,第二行是N个整数。1≤T≤10001≤N≤62hack时建议输出最后一行的行末回车;每一行的结尾不要输出空格。
输出描述
对于每组数据,输出一个数表示最大的乘积。
输入样例
131 2 3
输出样例
6
<pre name="code" class="html">#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;ll a[111];int main(){ int i,j,t,n,n1,n2,n3; ll ans,temp; cin>>t; while(t--) { cin>>n; n1=n2=n3=0; for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n); for(i=0;i<n;i++) { if(a[i]<0) n1++; else if(a[i]==0) n2++; else n3++; } if(n==1) { cout<<a[0]<<endl; continue; } ans=1; for(i=0;i<n;i++) { if(a[i]==0) continue; ans=ans*a[i]; } if(n2==n) { cout<<"0"<<endl; continue; } if(n3>0) { if(n1%2) ans=ans/a[n1-1]; cout<<ans<<endl; continue; } if(n1==1) { cout<<"0"<<endl; continue; } if(n1%2) { cout<<ans/a[n1-1]<<endl; continue; } cout<<ans<<endl; } return 0;}
0 0
- HDU GT and sequence (数的乘积最大)
- HDU 5504 GT and sequence(给一堆数,求最大值,坑比较多)
- HDU 5504:GT and sequence
- HDU 5504 GT and sequence
- HDU 5504 GT and sequence
- hdu 5504 GT and sequence(思维,逻辑,脑洞)
- hdu(5504)——GT and sequence
- HDU 5504 GT and sequence 模拟
- HDU 5504 GT and sequence(贪心)
- hdu 5504 GT and sequence(dp)
- GT and sequence 5504GT and sequence
- GT and sequence(bc模拟题)
- 5504 GT and sequence
- hdu5504 GT and sequence
- hdu5504 GT and sequence
- HDU_5504 GT and sequence
- GT and sequence
- hdu5504 GT and sequence
- error: unknown file type '.pyx' (from 'tsne/bh_sne.pyx')
- 虚拟化三剑客专题-VMware(上)
- 星际穿越的完全解析
- tomcat如何正确的开启远程调试功能
- 初学c语心得
- HDU GT and sequence (数的乘积最大)
- python_8(自定义模型使用、内置函数)
- 这学期的目标
- MySQL数据库基准压力测试工具之MySQLSlap使用实例
- 论自由
- 搜索引擎使用报告
- Android:ListView设置item点击背景效果
- Mac系统下Boot2Docker网络映射
- hdoj 5504 GT and sequence 【脑子 抽了】