hdu5504(水题,细节)
来源:互联网 发布:做淘宝培训 编辑:程序博客网 时间:2024/06/05 06:08
题目链接:hdu5504 GT and sequence
题目意思:给你n个数,要求你从中选取若干个数(最少一个)使得乘积最大。
思路:分清情况,注意细节。
#pragma GCC diagnostic error "-std=c++11"#include<iostream>#include<cmath>#include<cstdio>#include<algorithm>#include<string>#include<map>#include<climits>#include<vector>#include<queue>#include<set>#include<cstring>using namespace std;#define rep(i,a,b) for(int i=a;i<b;i++)#define CLR(a,b) memset(a,b,sizeof(a))#define maxn 1000010const int MOD = 1000000007;typedef long long ll;int main(){ios::sync_with_stdio(false);cin.tie(0);int n;int T;cin>>T;ll a[63];while(T--&&cin>>n) { ll ans=1; bool flag=false; vector<ll>v; for(int i=0;i<n;i++) { cin>>a[i]; if(a[i]) { ans*=a[i]; flag=true; } if(a[i]<0) v.push_back(a[i]); } if(!flag)//全为0的情况 { cout<<0<<endl; continue; } if(n==1)//只有一个数时 { cout<<a[0]<<endl; continue; } if(ans>0)//所有非0数乘积为正时 cout<<ans<<endl; else { int cnt=0; for(int i=0;i<n;i++) if(a[i]==0)cnt++; if(cnt==n-1&&v.size()==1&&v[0]==ans&&n>1)//有一个数为负数,其他数都是0时 { cout<<0<<endl; continue; } sort(v.begin(),v.end());//结果为负时将ans除以最大的负数 ans/=v.back(); cout<<ans<<endl; } }return 0;}
阅读全文
0 0
- hdu5504(水题,细节)
- hdu5504
- hdu5504
- hdu5504 GT and sequence(BestCoder Round #60 )
- hdu5504 GT and sequence
- hdu5504 GT and sequence
- hdu5504 GT and sequence
- 我家博宇生日快乐!!!hdu5504
- BestCoder Round #60 HDU5504 GT and sequence
- 小小细节(一)
- 平时细节(php)
- Java细节(9.22)
- Matlab细节(1)
- Matlab细节(2)
- Matlab细节(3)
- 各种细节(RP++)
- 集合细节(1)
- 集合细节(2)
- 通过JConsole查看本地远程虚拟机
- Django 用户修改密码
- 加密算法
- swift override和final的用法浅谈
- 枚举—案例(生理周期poj1006)
- hdu5504(水题,细节)
- Only one AsyncAnnotationBeanPostProcessor may exist within the context. 问题解决分享
- Nginx+Lua开发入门
- Swift——convenience(便利构造函数)和类方法
- 中小卖家电商节恐惧症:你们剁手,我们割肉 2017-10-27 09:00 稿源:懂懂笔记 0条评论 撤稿纠错 “其实对一部分我们这样的中小卖家来说,造节就是煎熬。” 在某大型电商平台上拥有两家
- 深入dubbo(四)配置参考
- android从入门到精通-项目实战(心得及源码)
- matlab数据类型
- 因为应用程序的并行配置不正确 sxstrace