zoukankan      html  css  js  c++  java
  • Masha and Bears(翻译+思维)

    Description

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

    Sample Input

    Input
    50 30 10 10
    Output
    50 30 10
    Input
    100 50 10 21
    Output
    -1

    Hint

    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.

     
    题目意思:熊爸爸,熊妈妈,熊儿子各有一辆车,车的体积是c1,c2,c3,他们一家的体积是v1,v2,v3,Masha的体积是vm。
    三辆车严格递减c1>c2>c3 。他们都喜欢各自的车满足条件vi<=ci<=2*vi。Masha三辆车都能进,但是他只喜欢最小的那辆车。
     
    解题思路;
    这道题很坑很坑,首先我们需要明确一点所给的是各自的体积,而要求的是汽车的体积!有用三层暴力的,其实在多种情况下只求一种,我们完全可以找一种边界情况,熊爸爸,熊妈妈不与Masha产生联系,还要严格递减,那么直接使用最大值就可以。c1=2*v1,c2=2*v2。但到了熊孩子就不一样了,他需要的车和Masha的需求产生了联系,Masha只喜欢最小的车而熊孩子也要最小车,这就使得我们需要对c3做一下判断。如果Masha体积很大,达到vm>2*v3,那么他将不能进入最小的车,不满足情况;但vm<=2*v3时,让c3等于熊孩子和Masha体积重最大的哪一个。这样c1,c2,c3找到了,接下来就是看是否符合条件了。
     我们要对所给的信息进行分析。
    1.Masha三辆车都能进,那么一定有vm<=c3。
    2.Masha要喜欢最小的那一辆车,那么还要满足2*vm>=c3
    3.Masha只喜欢最小的那一辆,那么说明不喜欢最大的和中间大的,那么2*vm<c1,2*vm<c2。
     
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #include <iostream>
     5 using namespace std;
     6 typedef long long int LL;
     7 const LL MAXL(1e6);
     8 int main()
     9 {
    10     int v1,v2,v3,vm;
    11     int c1,c2,c3;
    12     while(~scanf("%d%d%d%d",&v1,&v2,&v3,&vm))
    13     {
    14         c1=2*v1;
    15         c2=2*v2;
    16         if(vm>2*v3)
    17         {
    18             printf("-1
    ");
    19             return 0;
    20         }
    21         c3=max(v3,vm);
    22         if(vm<=c3&&2*vm>=c3&&2*vm<c2)
    23         {
    24             printf("%d
    %d
    %d
    ",c1,c2,c3);
    25         }
    26         else
    27         {
    28            printf("-1
    ");
    29         }
    30     }
    31     return 0;
    32 }
  • 相关阅读:
    python += 与=的区别
    django 使用框架下auth.models自带的User进行扩展增加字段
    基于服务器版centos7的Hadoop/spark搭建
    疑难汉字查询网
    中国地情网
    河南省高校社会科学研究信息网
    字由网站
    东方语言学
    北朝墓志地名查询
    子午书简——电子书网站
  • 原文地址:https://www.cnblogs.com/wkfvawl/p/9500615.html
Copyright © 2011-2022 走看看