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

相關文章
相關標籤/搜索