您的位置:首页 > 产品设计 > UI/UE

HDU 5504 GT and sequence

2015-10-30 20:35 288 查看
坑点比较多的一个题目

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

long long z[100],f[100];
int T,N;
int totz,totf,tot0;
long long  ans,x;

int main()
{
scanf("%d",&T);
while(T--)
{
totz=0;totf=0;tot0=0;
scanf("%d",&N);
for(int i=0;i<N;i++)
{
scanf("%lld",&x);
if(x==0) tot0++;
else if(x>0) z[totz++]=x;
else if(x<0) f[totf++]=x;
}
sort(f,f+totf);
if(totz>0)
{
ans=1;
for(int i=0;i<totz;i++) ans=ans*z[i];
if(totf%2==0)for(int i=0;i<totf;i++) ans=ans*f[i];
else for(int i=0;i<totf-1;i++) ans=ans*f[i];
}
else
{
if(totf==0) ans=0;
if(totf==1&&tot0==0) ans=f[0];
if(totf==1&&tot0!=0) ans=0;
if(totf>=2)
{
ans=1;
if(totf%2==0)for(int i=0;i<totf;i++) ans=ans*f[i];
else for(int i=0;i<totf-1;i++) ans=ans*f[i];
}
}
printf("%lld\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: