zoukankan      html  css  js  c++  java
  • UVA.10305 Maximum Product (暴力)

    UVA.10305 Maximum Product (暴力)

    题意分析

    直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可。

    代码总览

    #include <iostream>
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <sstream>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <cmath>
    #define nmax 10000
    #define MEM(x) memset(x,0,sizeof(x))
    int number[nmax];
    long long a[nmax];
    using namespace std;
    bool cmp(long long  x, long long y)
    {
        if(x>y) return true;
        else return false;
    }
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int n;int kase = 1;
        while(scanf("%d",&n) != EOF){
            MEM(a);MEM(number);
            for(int i = 1; i<=n; ++i) scanf("%d",&number[i]);
            int cnt = 0;
            for(int i = 1;i<=n;++i){
                for(int j = i; j<=n;++j){
                    if(j == i){
                        a[cnt++] = number[i];
                    }else{
                        a[cnt] = a[cnt-1] * number[j];
                        cnt++;
                    }
                }
            }
            sort(a,a+cnt,cmp);
            printf("Case #%d: The maximum product is %lld.
    
    ",kase++,a[0]>0?a[0]:0);
        }
        return 0;
    }
  • 相关阅读:
    Http中GET和POST两种请求的区别
    JSON学习笔记
    分页
    python 函数,闭包
    LVS负载均衡中arp_ignore和arp_annonuce参数配置的含义
    return ;
    openssl 在php里
    重装drupal
    protected的意义
    和 和 notepad++
  • 原文地址:https://www.cnblogs.com/pengwill/p/7367109.html
Copyright © 2011-2022 走看看