Codeforces 907A 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 ab , he or she likes it if and only if he can climb into this car and 2ab .

You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars.

很考验英语阅读能力的一道题,只需要把每只熊和车的关系理清楚就可以了。
题意大概是,每辆体积为 C 的车对一只体积为V的熊来说有下面三种可能:
不能进去的车 V>C
能进去但不喜欢的车 V<2V<C
喜欢的车 VC2V
设三辆车的大小为 C1,C2,C3 ,父亲、母亲、儿子、玛莎的体积分别为 V1,V2,V3,Vm
三辆车严格递减 C1>C2>C3
父亲,母亲,儿子分别喜欢三辆车 ViCi2Vi,(i=1,2,3)
玛莎三辆车都能进入,说明玛莎能进入最小的车: VmC1
玛莎只喜欢最小的车 C1 说明 2VmC1 ,并且玛莎不喜欢两辆车 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");
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值