zoukankan      html  css  js  c++  java
  • HDU 5504 GT and sequence

    坑点比较多的一个题目

    #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
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    Ubuntu系统下《汇编语言》环境配置

    GetDiskFreeSpaceEx的使用
    夏走了
    小笨妞
    项目管理怎么可以这样子!


    浪费
    查找文件夹
  • 原文地址:https://www.cnblogs.com/zufezzt/p/4924325.html
Copyright © 2011-2022 走看看