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

input output
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\right),\left ( 0,\frac{T}{2b_{2}}\right),\left ( \frac{T-b_{2}m}{a_{2}},m\right),\left ( n,\frac{T-a_{2}n}{b_{2}}\right)\]取最优解即可
 
 
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
double ans = ;
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 = ,y = ;
if(x1 >= && x1 <= n){
if(x1*a1>=ans){
ans = x1*a1;
x = x1,y=;
}
}else if(y1 >= && y1 <=m){
if(y1*b1>=ans){
ans = y1*b1;
x = , y = y1;
}
}else if(x2 >= && x2 <= n){
if(x2*a1 + m*b1 >=ans){
ans = x2*a1 + m*b1;
x = x2,y=m;
}
}else if(y2 >= && y2 <= m){
if(n*a1 + y2*m >= ans){
ans = n*a1+y2*m;
x = n,y=y2;
}
}
printf("%.8f %.8f\n",x,y);
return ;
}

Cake URAL - 1755的更多相关文章

  1. Windows 7上执行Cake 报错原因是Powershell 版本问题

    在Windows 7 SP1 电脑上执行Cake的的例子 http://cakebuild.net/docs/tutorials/getting-started ,运行./Build.ps1 报下面的 ...

  2. 2015暑假多校联合---Cake(深搜)

    题目链接:HDU 5355 http://acm.split.hdu.edu.cn/showproblem.php?pid=5355 Problem Description There are m s ...

  3. Scalaz(15)- Monad:依赖注入-Reader besides Cake

    我们可以用Monad Reader来实现依赖注入(dependency injection DI or IOC)功能.Scala界中比较常用的不附加任何Framework的依赖注入方式可以说是Cake ...

  4. uva10167 Birthday Cake

    Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them. Now we put t ...

  5. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  6. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  7. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  8. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  9. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

随机推荐

  1. Docker系列三:Dockerfile

    Dockerfile是由一系列命令和参数构成的脚本,这些命令应用于基础镜像并最终创建一个新的镜像 Dockerfile由一行行命令语句组成,支持#开头的注释 Dockerfile分为四部分:基础镜像信 ...

  2. 关于Apache Commons-Lang3的使用

    在日常工作中,我们经常要使用到一些开源工具包,比如String,Date等等.有时候我们并不清楚有这些工具类的存在,造成在开发过程中重新实现导致时间浪费,且开发的代码质量不佳.而apache其实已经提 ...

  3. 《C Prime Plus》第九节笔记

    第九节 函数 9.1 复习函数 函数原型 function prototype 函数调用 function call 函数定义 function definition 形参 实参 典型的ANSI C函 ...

  4. Android 7.0终极开发者预览版全攻略!

    近日,Google的工程部副总裁Dave Burke在官方博客上正式发布开发者预览版5,此预览版是android 7.0 “牛轧糖”正式发布前最后一个预览版,同时也是在性能.功能上等多方面的表现上最接 ...

  5. peewee 对 mysql 类型支持问题,并不支持bit

    这个问题是当时想当然了 看到python BooleanField(default=False) 便认为 对应 mysql的bit 出现问题 mysql实际字段存储值为0,但 peewee orm 后 ...

  6. MSSS攝影大賽計劃書(第三版)

    比賽內容:對香港的城市風景以及自然風光的攝影 預期成果: 提升同學對香港的認識,鼓勵學生走出大學學園去瞭解香港,同時豐富會員的課餘活動,培養同學的興趣愛好 比賽時間:4月1-15日 最後作品提交時間: ...

  7. java和javascript日期详解

    ** java,js日期转换:** <Excerpt in index | 首页摘要> java的各种日期转换 <The rest of contents | 余下全文> 日期 ...

  8. Steve Lin:如何撰写一篇优秀的SIGGRAPH论文

    Lin:如何撰写一篇优秀的SIGGRAPH论文" title="Steve Lin:如何撰写一篇优秀的SIGGRAPH论文"> 英文原版 PPT下载:http:// ...

  9. 浅谈URL重定向

    转载:https://blog.csdn.net/kiyoometal/article/details/90698761 重定向原理 HTTP 协议的重定向响应的状态码为 3xx .浏览器在接收到重定 ...

  10. 18.09.22模拟赛T2 历史

    网上基本上找不到这道题,何况LJJ还稍微改了一下...... 原题:传送门 题目描述 ljj 被S 国数不清的漂亮小姐姐所吸引,为了搞清楚为什么S 国有如此多的漂亮小姐姐,他决定研究S 国的历史. 根 ...