Sugar Water(AtCoder-3534)

Problem Description

Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.

Operation 1: Pour 100A grams of water into the beaker.
Operation 2: Pour 100B grams of water into the beaker.
Operation 3: Put C grams of sugar into the beaker.
Operation 4: Put D grams of sugar into the beaker.
In our experimental environment, E grams of sugar can dissolve into 100 grams of water.

Snuke will make sugar water with the highest possible density.

The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker. Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it. If there is more than one candidate, any of them will be accepted.

We remind you that the sugar water that contains a grams of water and b grams of sugar is 100b/(a + b) percent. Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.

Constraints

  • 1 <=  A < B <= 30
  • 1 <= C < D <= 30
  • 1 <= E <= 100
  • 100A <= F <= 3 000
  • A, B, C, D, E and F are all integers.

Input

Input is given from Standard Input in the following format:

A B C D E F

Output

Print two integers separated by a space. The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.

Example

Sample Input 1

1 2 10 20 15 200

Sample Output 1

110 10
In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.

We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once. It is not possible to make sugar water with higher density. For example, the following sequences of operations are infeasible:

If we perform Operation 1 once and Operation 4 once, there will be undissolved sugar in the beaker.
If we perform Operation 2 once and Operation 3 three times, the mass of substances in the beaker will exceed 200 grams.

Sample Input 2

1 2 1 2 100 1000

Sample Output 2

200 100
There are other acceptable outputs, such as:

400 200
However, the output below is not acceptable:

300 150
This is because, in order to make 300 grams of sugar water containing 150 grams of sugar, we need to pour exactly 150 grams of water into the beaker, which is impossible.

Sample Input 3

17 19 22 26 55 2802

Sample Output 3

2634 934

题意:制作糖水,一开始烧杯是空的,可以执行以下操作任意次:将 100A 克水倒入烧杯、将 100B 克水倒入烧杯、将 C 克糖倒入烧杯、将 D 克糖倒入烧杯,现已知 E 克糖可以溶于 100 克水中,烧杯最多含有 F 克的物质且烧杯中不允许有未溶解的糖,现在要制作浓度尽可能高的糖水,问糖水和糖的质量

思路:由于所给的 A、B、C、D、E、F 的范围都不是很大,因此直接暴力枚举所有情况即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int main() {
    int A,B,C,D,E,F;
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);

    int sugarWater=-1,sugar=1;
    for(int i=0;i*100*A<=F;i++){//水A
        int waterA=i*100*A;
        for(int j=0;j*100*B<=F-waterA;j++){//水B
            int waterB=j*100*B;
            for(int k=0;k*C<=F-waterA-waterB;k++){//糖C
                int sugarC=k*C;
                for(int t=0;t*D<=F-waterA-waterB-sugarC;t++){//糖D
                    int sugarD=t*D;
                    int sugarSum=sugarC+sugarD;//糖质量
                    int tot=waterA+waterB+sugarSum;//当前质量
                    int real=A*E*i+B*E*j;//当前可放的糖
                    if(real<sugarSum||tot>F)
                        continue;
                    if(tot!=0&&sugarSum*1.0/tot>sugar*1.0/sugarWater){
                        sugar=sugarSum;
                        sugarWater=tot;
                    }
                }
            }
        }
    }
    printf("%d %d\n",sugarWater,sugar);

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值