zoukankan      html  css  js  c++  java
  • Cake URAL

    1755. Cake

    Time limit: 0.5 second
    Memory limit: 64 MB
    Karlsson and Little Boy have found a cake in the fridge. It is written on the box that the cake consists of n grams of cream, m grams of chocolate, and other ingredients. The friends want to divide the cake between them and eat it right there.
    Little Boy is going to cut the cake into two pieces, and then Karlsson will choose the piece that he thinks is more delicious. Little Boy agrees with this method of dividing, because his and Karlsson's tastes differ and so he can cut the cake in such a way that he would get a piece that is not so bad. In addition, Karlsson is so kind that if the two pieces seem equally delicious to him then he will let Little Boy choose.
    If a piece of cake contains x grams of cream and y grams of chocolate, then Little Boy evaluates the deliciousness of this cake by the number ax + by. Karlsson evaluates the same piece by the numberax + by. Given the coefficients a1, b1, a2, b2, tell Little Boy how to cut the cake so that he would get as delicious piece of cake as possible. Little Boy can cut off a piece containing any amount of cream and any amount of chocolate but, of course, no more than there is in the whole cake.

    Input

    The first line contains the integers a1, b1, a2, b2 (0 ≤ aibi ≤ 100). The second line contains the integers nand m (0 ≤ nm ≤ 1000).

    Output

    Output the mass of cream and the mass of chocolate in one of the pieces into which Little Boy should cut the cake accurate to 10−8. It does not matter who will get this piece. If there are several optimal answers, output any of them.

    Sample

    inputoutput
    1 2 3 2
    400 300
    
    300.00000000 0.00000000
    Problem Author: Vladislav Isenbaev
    Problem Source: XI USU Open Personal Contest (March 13, 2010)
    Tags: none  (
    hide tags for unsolved problems
    题目大意:有块蛋糕,蛋糕有n奶油m巧克力。Karlsson 和Little Boy要分这块蛋糕为二,Karlsson对蛋糕的美味度为a1x+b1y、Little Boy对蛋糕的美味度为a2x+b2y两人都想取自己认为最美味的那块蛋糕。Little Boy负责切蛋糕,Karlsson先选自己喜欢的那块。假设蛋糕的巧克力和奶油可以任意分配,问Karlsson 如何切蛋糕能保证自己拿到的美味度尽可能高。
     
    思路:因为a1,b1,a2,b2均为正数,所以分得的蛋糕越大,美味度越高。则两块蛋糕在Karlsson面前,Karlsson认为的美味度都是一样时[T=frac{a1*n+a2*m}{2}]
    可以保证Little Boy能有机会取的自己认为美味度最大的蛋糕。然后要使Karlsson分得的美味度最大,如果Karlsson更喜欢巧克力那就巧克力多分点,反之亦然。从[left ( frac{T}{2a_{2}},0 ight),left ( 0,frac{T}{2b_{2}} ight),left ( frac{T-b_{2}m}{a_{2}},m ight),left ( n,frac{T-a_{2}n}{b_{2}} ight)]取最优解即可
     
     
    #include<iostream>
    #include<cstdio>
    using namespace std;
    int main(){
        double ans = 0;
        double a1,b1,a2,b2;
        double n,m,T;
        cin>>a1>>b1>>a2>>b2;
        cin>>n>>m;
        T = (n*a2+m*b2)/2.0;
        double x1;
        double x2;
        double y1;
        double y2;
        x1 = T/a2;
        y1 = T/b2;
        x2 = (T-b2*m)/a2;
        y2 = (T-a2*n)/b2;
        double x = 0,y = 0;
        if(x1 >= 0 && x1 <= n){
            if(x1*a1>=ans){
                ans = x1*a1;
                x = x1,y=0;
            }
        }else if(y1 >= 0 && y1 <=m){
            if(y1*b1>=ans){
                ans = y1*b1;
                x = 0, y = y1;
            }
        }else if(x2 >= 0 && x2 <= n){
            if(x2*a1 + m*b1 >=ans){
                ans = x2*a1 + m*b1;
                x = x2,y=m;
            }
        }else if(y2 >= 0 && y2 <= m){
            if(n*a1 + y2*m >= ans){
                ans = n*a1+y2*m;
                x = n,y=y2;
            }
        }
        printf("%.8f %.8f
    ",x,y);
        return 0;
    }
  • 相关阅读:
    洛谷春季多校第四场
    HZNU Training 8 for Zhejiang Provincial Competition 2020
    HZNU Training 6 for Zhejiang Provincial Competition 2020
    二分图
    HZNU Training 5 for Zhejiang Provincial Competition 2020
    洛谷春季 ACM 多校训练第二周
    HZNU Training 2 for Zhejiang Provincial Competition 2020
    TestNG入门教程-12-Java代码执行testng.xml和失败后重跑
    eclipse导出可执行jar包步骤
    创建可执行的JAR包并运行
  • 原文地址:https://www.cnblogs.com/zhenggaoxiong/p/9727972.html
Copyright © 2011-2022 走看看