Masha and Bears
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.
Input
You are given four integers V1, V2, V3, Vm(1 ≤ Vi ≤ 100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V1 > V2 > V3.
OutputOutput three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes).
Examples50 30 10 10
50 30 10
100 50 10 21
-1
In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20.
给定体重w,能进入这辆车车的大小要求szie >= w,如果这个人还喜欢这辆车需要满足 w <= size <= 2*w
题目给定a,b,c,d四个人重量,abc喜欢各自的车,并且a>b>c,d能进去abc的三辆车car1,car2,car3并且只喜欢第三辆车,求满足条件的三辆车的大小
首先从喜欢car3入手,所以必须满足 c <= d <= 2*c,即如果d > 2*c || 2*d < c不行,第一个不等式好说,第二个容易写错,因为car3的大小在c~2*c 所以只要2*d能在这个范围内就能保证喜欢这辆车,其次对于car2,如果d < b我们让car2取最大2*b就可以满足不喜欢car2,那么同理最大的车car1也取最大值2*a就可以了,第三辆车输出max(d,c)
code:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
int a,b,c,d;
cin >> a >> b >> c >> d;
if(d > 2 * c || c > 2 * d || d >= b)
printf("-1\n");
else
printf("%d\n%d\n%d\n",2*a,2*b,max(c,d));
return 0;
}