題目: UVa - 11689 - Soda Surpler

題目說明

有一個人很喜歡喝汽水,汽水可以使用空瓶兌換,每組測資給三個整數 efc,分別代表 初始擁有的空瓶數量找到的空瓶數量兌換一瓶汽水需要的空瓶數量

Input: 第一個整數 T 代表有 T 組測資,每組一行,每行有三個整數分別代表 efc

Output: 輸出最多能喝到幾瓶汽水。

解題思路

根據題意模擬即可,e + f 為一開始擁有的空瓶數量,需要注意的是,兌換到的汽水也要加進空瓶的數量

參考解法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>

using namespace std;

static auto __ = []
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
return 0;
}();

int main()
{
// e -> empty, f -> found, c -> cost
int T, e, f, c, ret;
cin >> T;
while (T--)
{
cin >> e >> f >> c;
ret = 0;
e += f; // total empty bottles
while (e >= c)
{
int bottles = e / c;
ret += bottles;
e = bottles + e % c;
}
cout << ret << '\n';
}
}