Design road

Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1548


Mean:

目的:从(0,0)到达(x,y)。但是在0~x之间有n条平行于y轴的河,每条河位于xi处,无限长,wi宽,并分别给出了建立路和桥每公里的单价

求:到达目标的最小费用。

analyse:

比赛的时候一直没想到思路,第二个样列怎么算都算不对,赛后才知道是三分。

首先把所有的桥移到最右端,然后三分枚举路和河的交点。

Time complexity: O(logn)

Source code: 

//  Memory   Time
// 1347K 0MS
// by : crazyacking
// 2015-03-30-21.24
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#define MAXN 1000010
#define LL long long
using namespace std;
double x,y,c1,c2,sum,xx;
double calc(double mid)
{
double road_cost=sqrt(xx*xx+mid*mid)*c1, bridge_cost=sqrt(sum*sum+(y-mid)*(y-mid))*c2;
return road_cost+bridge_cost;
} double solve(double low,double high)
{
double l=low,h=high;
double mid=(l+h)/,mmid=(mid+h)/;
double cmid=calc(mid),cmmid=calc(mmid);
while(fabs(cmmid-cmid)>=1e-)
{
if(cmid>cmmid)
l=mid;
else
h=mmid;
mid=(l+h)/,mmid=(mid+h)/;
cmid=calc(mid),cmmid=calc(mmid);
}
return min(cmmid,cmid);
} int main()
{
int n;
while(cin>>n>>x>>y>>c1>>c2)
{
sum=0.0;
double tmp1,tmp2;
for(int i=;i<=n;++i)
{
cin>>tmp1>>tmp2;
sum+=tmp2;
}
xx=x-sum;
printf("%.2lf\n",solve(0.0,y));
}
return ;
}

三分 --- CSU 1548: Design road的更多相关文章

  1. CSU 1548 Design road(三分查找)

    题目链接:https://cn.vjudge.net/problem/142542/origin Description You need to design road from (0, 0) to ...

  2. 1548: Design road (思维题 做法:三分找极值)

    1548: Design road Submit Page    Summary    Time Limit: 2 Sec     Memory Limit: 256 Mb     Submitted ...

  3. csu 1548(三分)

    1548: Design road Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 383  Solved: 200[Submit][Status][We ...

  4. Contest2071 - 湖南多校对抗赛(2015.03.28)

    Contest2071 - 湖南多校对抗赛(2015.03.28) 本次比赛试题由湖南大学ACM校队原创 http://acm.csu.edu.cn/OnlineJudge/contest.php?c ...

  5. csu 1947 三分

    题意: 长者对小明施加了膜法,使得小明每天起床就像马丁的早晨一样. 今天小明早上6点40醒来后发现自己变成了一名高中生,这时马上就要做早操了,小明连忙爬起来 他看到操场密密麻麻的人,突然灵光一闪想到了 ...

  6. Design and Analysis of Algorithms_Brute Froce

    I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...

  7. (转)The Road to TensorFlow

    Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a ...

  8. Indian Scientists Design Device to Collect Solar Energy 印度科学家设计太阳能收集设备

      Indian scientists have designed a new device they hope will solve one of the biggest problems with ...

  9. Principles of good RESTful API Design 好的 RESTful API 设计

    UPDATE: This post has been expanded upon and converted into an eBook. Good API design is hard! An AP ...

随机推荐

  1. Hbase&Hadoop常用命令

    Hbase中根据Rowkey的前缀Prefix查询数据: scan 'test_xiaomifeng_monitoring_log',{FILTER => "(PrefixFilter ...

  2. pgpgin|pgpgout|pswpin|pswpout意义与差异

    引用来自: http://ssms.cs2c.com.cn/otrs/pc.pl?Action=PublicFAQZoom;ItemID=11741 文章主要意思是: 1. page in/out操作 ...

  3. wordpress自动截取文章摘要代码

    想要实现 wordpress 首页显示摘要有几种方法: 第一种,可以在写文章的时侯在需要分割的地方加入<!–more–>标签,但在输出首页摘要的同时,也会使feed只显示摘要,不方便读者阅 ...

  4. 关于 Redis 访问安全性的问题

    升级版本 3.0.2 版本升级到 redis-3.2.0 版本远程无法访问,比较配置文件有些变化,比如默认只能本地的机器才能访问 3.0.2 版本 # By default Redis listens ...

  5. C#中操作xml文件(插入节点、修改、删除)

    已知有一个xml文件(bookstore.xml)如下: <?xml version="1.0" encoding="gb2312"?> <b ...

  6. GPL与LGPL的区别

    GPL(GNU General Public License)  我们很熟悉的Linux就是采用了GPL.GPL协议和BSD, Apache Licence等鼓励代码重用的许可很不一样.GPL的出发点 ...

  7. Angular 使用

    tks: 使用: http://developer.51cto.com/art/201302/380661.htm http://www.infoq.com/cn/news/2013/02/angul ...

  8. OpenGL es3.0 初始化及渲染

    class FOpenglEs { public: /** * 初始化 OpenGLES3.0 */ bool initOpenGLES30(HWND hwnd) { EGLConfig config ...

  9. “远程调试监视器(MSVSMON.EXE)似乎没有在远程计算机上运行“的完美解决方案

    今天调试程序时,Visual Studio突然报出了如下错误: Microsoft Visual Studio 远程调试监视器(MSVSMON.EXE)似乎没有在远程计算机上运行.这可能是因为防火墙阻 ...

  10. iOS 复选框做法

    -(void)checkboxClick:(UIButton *)btn{    btn.selected = !btn.selected;} - (void)viewDidLoad {UIButto ...