• UVALive 5840 数学题


    DES:给出三种材料A,B,C每种的个数。然后组合AB,BC,AC的利润。问能获得的最大利润是多少。

    开始一点思路都没有。然后发现可以枚举其中两种的个数。那么最后一种就确定了。还是感觉很机智。

    #include<stdio.h>
    #include<iostream>
    #include<string.h>
    using namespace std;
    
    int main()
    {
        int t;
        int ab, bc, ac;
        int a, b, c;
        scanf("%d
    ", &t);
        while(t--)
        {
            scanf("%d%d%d%d%d%d", &a, &b, &c, &ab, &bc, &ac);
            int ans = 0;
            //cout << "ab bc ac
    ";
            for (int i=0; i<=a; ++i) //ab
            {
                for (int j=0; j<=b-i; ++j) //bc
                {
                    int tt;
                    if (a-i > c-j) tt = c-j;  //ac
                    else tt = a-i;
                    if (tt < 0) continue;
                    //cout << tt << "==
    ";
                    if (i+j>b || i+tt>a || j+tt>c) continue;
                    int ttt = ab*i + j*bc + tt*ac;
                    //cout << i << "==" << j << "==" << tt << endl;
                    //cout << ttt << endl;
                    if (ans < ttt) ans = ttt;
                }
            }
            printf("%d
    ", ans);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    2017年9月22日 关于JS数组
    2017年9月20日
    2017年9月19日 JavaScript语法操作
    2017年9月18日
    2017年9月17日 JavaScript简介
    2017年9月16日
    2017年9月15日
    2017年9月14日
    2017年9月12日
    贪吃蛇全文
  • 原文地址:https://www.cnblogs.com/icode-girl/p/4731218.html
Copyright © 2020-2023  润新知