A. Two Vessels

A. Two Vessels

Two Vessels contest
Two Vessels problemset
一道诈骗题。

Problem

给你三个杯子,前两个杯子分别装着 \(a\)\(b\) 克水,第三个杯子里是空的,最多能装 \(c\) 克水。每次你能从任意杯子里取出 \(c\) 克水,并将它倒入到另一个杯子里,且每次可以倒 \(x\space(0 < x \le c)\) 克水到一个杯子里。问最少要多少次才能使两个杯子里的水一样多。

Solution

每次将谁更多的那一瓶水一直倒出 \(c\) 克水到另外一瓶水,最后不满 \(c\) 克水的差距也只用一次,因为每一次可以倒任意克水。

AC Code

#include "bits/stdc++.h"

using std::cin;
using std::cout;

const double eps = 1e-8;

double max(double a,double b)
{
	return a > b ? a : b;
}

double min(double a,double b)
{
	return a < b ? a : b;
}

int solve(double a,double b,double c)
{
	return (int) std::ceil( ( max(a,b) - min(a,b) ) / c / 2 );
}

int main()
{
	cin.tie(0);
	std::ios::sync_with_stdio(0);
	int T;
	cin >> T;
	
	while (T--)
	{
		int a,b,c;
		cin >> a >> b >> c;
		cout << solve(a,b,c) << '\n';
	}
	
	return 0;
}
posted @ 2023-09-18 20:48  Laughing_xxx  阅读(31)  评论(0)    收藏  举报