HDU 5504 GT and sequence(贪心)
来源:互联网 发布:数据可视化软件 编辑:程序博客网 时间:2024/05/20 00:52
题目大意:给定一个序列,任选出序列中的数字,并输出其组成的最大数.
思路:就是一个简单的贪心吧,但是注意各组数据的各种坑.如当只有一个数的时候,permutation中含有0,
其中有负数,0,正数等等情况.
#include<iostream>#include<cstdio>#include<cstring>#include<map>#include<algorithm>#define ll __int64#define inf 0x3f3f3f3fusing namespace std;ll a[1000000];int main(){ ll n,m,i,j,k,mi,s; ll cla,zero,fu; scanf("%I64d",&cla); while(cla--) { mi=-inf;zero=fu=0; s=1; scanf("%I64d",&n);bool vis=false; for(i=0;i<n;i++) { scanf("%I64d",a+i); if(a[i]!=0) vis=true; if(a[i]<0) { fu++; mi=max(mi,a[i]); } if(!a[i]) zero++; } if(!vis) { printf("0\n");continue; } if(n==1) { printf("%I64d\n",a[0]);continue; } if(fu==1&&(fu==n-zero)) { printf("0\n"); continue; } for(i=0;i<n;i++) { if(a[i]) s*=a[i]; } if(s<0) { printf("%I64d\n",s/mi);continue; } printf("%I64d\n",s); } return 0;}
0 0
- 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
- 5504 GT and sequence
- hdu 5504 GT and sequence【BestCoder Round #60 】
- hdu 5504 GT and sequence(思维,逻辑,脑洞)
- HDOJ 5504-GT and sequence
- HDOJ 5504 GT and sequence (乱搞)
- 杭电5504 GT and sequence
- 杭电-5504GT and sequence
- hdu5504 GT and sequence
- hdu5504 GT and sequence
- HDU_5504 GT and sequence
- C++ assert
- TortoiseSVN+金山快盘打造个人SVN环境
- 淘宝运营:用户体验闯四关 让你的客户对你念念不忘
- Java单例模式——黑马训练营
- 万年历
- HDU 5504 GT and sequence(贪心)
- Win32 API函数
- CSS Display(显示) 与 Visibility(可见性)
- ProtocolBuffer安装与使用小结
- JAVA 中的fillOval方法和drawline方法
- 九度OJ 1082:代理服务器 (DP)
- Windows AD中批量修改用户属性
- yii2.0环境搭建
- poj1155 TELE