Вопрос скорее будет звучать "как много могли съесть толстяки?".
#include <iostream>
using namespace std;
int main() {
int multiplier = 1;
float weightCake = 0;
float t1(0), t2(0), t3(0);
float t1Cakes(0), t2Cakes(0), t3Cakes(0);
cout << "Weight of cake, fat people 1-3: ";
cin >> weightCake; cin >> t1; cin >> t2; cin >> t3;
while(1) {
t1Cakes = multiplier * weightCake * 1;
if(t1Cakes > t1/2) {
cout << multiplier - 1;
break;
}
t2Cakes = multiplier * weightCake * 2;
if(t2Cakes > t2/2) {
t3Cakes = multiplier * weightCake * 4;
if(t3Cakes > t3/2) {
++multiplier;
typedef long long ll;
bool ll_is_valid(ll t, ll N, ll x, ll y)
{
return t / x + (t - x) / y >= N;
ll f(ll N, ll x, ll y)
ll R = 1;
while (!ll_is_valid(R,N,x,y)) R *= 2;
ll L = R / 2;
while(R - L > 1)
ll M = (L + R) / 2;
if (!ll_is_valid(M,N,x,y)) {L = M;}
else {R = M;}
return R;
int main()
ll N,x,y;
cin >> N >> x >> y;
if(x > y) swap( x, y );
cout << f(N, x, y) << std::endl;
Вопрос скорее будет звучать "как много могли съесть толстяки?".
#include <iostream>
using namespace std;
int main() {
int multiplier = 1;
float weightCake = 0;
float t1(0), t2(0), t3(0);
float t1Cakes(0), t2Cakes(0), t3Cakes(0);
cout << "Weight of cake, fat people 1-3: ";
cin >> weightCake; cin >> t1; cin >> t2; cin >> t3;
while(1) {
t1Cakes = multiplier * weightCake * 1;
if(t1Cakes > t1/2) {
cout << multiplier - 1;
break;
}
t2Cakes = multiplier * weightCake * 2;
if(t2Cakes > t2/2) {
cout << multiplier - 1;
break;
}
t3Cakes = multiplier * weightCake * 4;
if(t3Cakes > t3/2) {
cout << multiplier - 1;
break;
}
++multiplier;
}
}
#include <iostream>
typedef long long ll;
using namespace std;
bool ll_is_valid(ll t, ll N, ll x, ll y)
{
return t / x + (t - x) / y >= N;
}
ll f(ll N, ll x, ll y)
{
ll R = 1;
while (!ll_is_valid(R,N,x,y)) R *= 2;
ll L = R / 2;
while(R - L > 1)
{
ll M = (L + R) / 2;
if (!ll_is_valid(M,N,x,y)) {L = M;}
else {R = M;}
}
return R;
}
int main()
{
ll N,x,y;
cin >> N >> x >> y;
if(x > y) swap( x, y );
cout << f(N, x, y) << std::endl;
}