A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It’s known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car.
Masha came to test these cars. She could climb into all cars, but she liked only the smallest car.
It’s known that a character with size a can climb into some car with size b if and only if a ≤ b, he or she likes it if and only if he can climb into this car and 2a ≥ b.
You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.
很考验英语阅读能力的一道题,只需要把每只熊和车的关系理清楚就可以了。
题意大概是,每辆体积为C的车对一只体积为
不能进去的车V>C;
能进去但不喜欢的车V<2V<C;
喜欢的车V≤C≤2V。
设三辆车的大小为C1,C2,C3,父亲、母亲、儿子、玛莎的体积分别为V1,V2,V3,Vm
三辆车严格递减 C1>C2>C3
父亲,母亲,儿子分别喜欢三辆车 Vi≤Ci≤2Vi,(i=1,2,3)
玛莎三辆车都能进入,说明玛莎能进入最小的车:Vm≤C1
玛莎只喜欢最小的车C1说明2Vm≤C1,并且玛莎不喜欢两辆车2Vm<C2,2Vm<C3
只要能选出三辆车满足整理所有条件就行了,下面上代码(为了统一我把<和>都换成了≤和≥)
#include <stdio.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)>(b)?(b):(a))
int main() {
int father, mother, son, masha;
int car1, car2, car3;
scanf("%d %d %d %d", &father, &mother, &son, &masha);
bool flag = false;
for (car3 = max(son,masha); car3 <= min(2*son,2*masha)&&flag==false; ++car3) {
for (car2 =max(mother, max(car3+1,2*masha+1)); car2 <= 2*mother && flag == false; ++car2) {
for (car1 =max(father, max(car2+1,2*masha+1)); car1 <= 2*father && flag == false; ++car1) {
flag = true;
printf("%d\n%d\n%d", car1, car2, car3);
}
}
}
if (flag == false)printf("-1");
}