Codeforces Round #454 A. Masha and Bears

本文解析了 CodeForces 平台上的 907A 题目,该题涉及逻辑判断与数值计算。文章详细阐述了解题思路与核心算法,并附带完整的 C++ 代码实现。

题目链接:http://codeforces.com/contest/907/problem/A

A. Masha and Bears
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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).

Examples
Input
Copy
50 30 10 10
Output
Copy
50
30
10
Input
Copy
100 50 10 21
Output
Copy
-1
Note

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.

题目大意:

给你4个尺寸,分别是熊爸,熊妈,熊儿子,和masha的。然后让你给出3辆车的尺寸。这三辆车严格递减,分别是让熊爸,熊妈和熊儿子坐的并且masha喜欢做最小的内辆车。假设车的尺寸是b,那么a喜欢尺寸为b的车的条件是a<=b并且2*a>=b.注意不能让masha喜欢上中等及以上尺寸的车。

思路:

要想让masha能够坐进最小的车,那么最小车的尺寸b就必须大于等于masha 的尺寸a1,并且2*a1>=b.同时还需要保证b大于等于熊儿子的尺寸a2,同时2*a2>=b.最后还需要保证中等车的尺寸B满足B>2*a2.于是就转换成熊妈妈的尺寸a3>a2.以上条件不满足就输出-1

#include<string.h>
#include<iostream>
#include<algorithm>
#include<stdio.h>
#define ll long long
using namespace std;
int  main()
{
    int v1,v2,v3,v4;
    cin>>v1>>v2>>v3>>v4;
    if(v3*2<v4||v3>2*v4||v4>=v2)
    {
        cout<<-1<<endl;
    }
    else
    {
        if(v3>v4)
        {
            cout<<2*v1<<endl;
            cout<<2*v2<<endl;
            cout<<v3<<endl;
        }
        else
        {
            cout<<2*v1<<endl;
            cout<<2*v2<<endl;
            cout<<v4<<endl;
        }

    }
    return 0;
}
另外,这场的题意是真的有点坑。。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值