Codeforces Round #454 Div. 2 A

题目:A. 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.
Output
Output 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).less

样例:
Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1this

提示:
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.code

大致意思:这个题的大致意思就是,3个熊都能爬到一辆车中,父亲爬最大的,母亲爬中等的,小熊爬最小的,而且每一个熊都喜欢他们所爬的这辆车。a为熊的体积,b为车的体积。并且他们喜欢一辆车的条件是他们能爬上这辆车即b>=a,并且还要知足2a>=b。这样才能够,可是并无说只喜欢本身爬上的这辆车。masha则是均可以爬上车,可是只喜欢小车。而后依次输入三个熊的体积和masha的体积,看可否有合适的三辆车存在,若是存在则输出,不存在则输出-1;three

思路:当时作的时候先分析了这题的类型,这题为是非问题,因此判断条件的寻找就显得很是重要,这里当初先把三只熊的三辆车的范围经过数学中数轴画出来,而后再把masha的车的范围也在数轴上标出,由于masha可以进入因此车,也就是说masha的体积比最小的车还小,但又由于masha还有喜欢小车,因此masha车的范围要和小熊的车的范围有交集才能保证有解,并且题目中还说只能喜欢小车,因此说masha的车的范围与母熊即中等的车有交集,但不能够覆盖,即中等车的范围有比masha的车的最大范围还大的,这样才能够有解;接下来是输出问题,大车只须要知足父熊的范围就能够,因此随便哪一个均可以。小车则要知足masha和小熊均可以才行,即小车只要是大于二者之间最大的体积,小于二者之间两倍的最小的就能够。中等车要知足母熊且要保证两倍的masha是小于中等车的体积就能够;ip

过程当中学到的新技巧:就是经过数学数轴的方法,将题目内的数值范围转换在数学中的交集问题;数学

代码:it

include<stdio.h>

int main()
{io

int a,b,c,x,t;
   scanf("%d%d%d%d",&a,&b,&c,&x);
   if(x<b&&x<=2*c&&2*x>=c)
   {
       t=x>c?x:c;
       printf("%d\n",a>(2*b+1)?a:(2*b+1));
       printf("%d\n",b>(t*2+1)?b:(t*2+1));
       printf("%d\n",t);
   }
   else
       printf("-1\n");
   return 0;

}test

相关文章
相关标签/搜索