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. WPF TextBox自动滚动到最户一行

    textBox经常用来显示程序的运行状态或者消息,如何让他自动滚动呢? 在显示消息代码下加一条自动滚动到底部的语句即可: TextBox1.ScrollToEnd(); (如果要显示垂直滚动条设置Ve ...

  2. ASP.NET 4.0 forms authentication issues with IE11

    As I mentioned earlier, solutions that rely on User-Agent sniffing may break, when a new browser or ...

  3. javascript不用new关键字创建对象示例

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  4. eclipse新建一个Android项目,就会报错android.support.v7.app.ActionBarActivity

    解决方法: 今天被这个问题折腾了一下,最后终于找到了解决办法. 产生这个问题,是因为你升级了ADT到version 22,但是还需要升级SDK Tools,Platform Tools,Build T ...

  5. Oracle查找全表扫描的SQL语句

    原文链接:http://blog.itpub.net/9399028/viewspace-678358/ 对于SQL的执行计划,一般尽量避免TABLE ACCESS FULL的出现,那怎样去定位,系统 ...

  6. iOS项目立项

    哎,计划总是赶不上变化,仿佛又回到了十年前高三的时候,每月.每周.每天都有计划,但是每周.每天都有计划外的因素导致了计划时时变,唯一不变的就只有变化了. 想了许久,中期计划内还是转回iOS吧,说转回其 ...

  7. 调用 google speech api (使用Google语音识别引擎)

    完全参考自: http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/ http://aiku.me/bar/104480 ...

  8. mac vim 使用

    再使用Mac编辑文件时感觉非常不爽,没有语法高亮,只能通过设置改变所有字体为同一个颜色,看起来还是别扭, 于是找到方法使用vim时可以实现语法高亮显示,操作步骤如下: 1.进入/usr/share/v ...

  9. oracle create table(转)

    //建测试表 create table dept( deptno number(3) primary key, dname varchar2(10), loc varchar2(13) ); crea ...

  10. 牛顿方法(Newton-Raphson Method)

    本博客已经迁往http://www.kemaswill.com/, 博客园这边也会继续更新, 欢迎关注~ 牛顿方法是一种求解等式的非常有效的数值分析方法. 1.  牛顿方法 假设\(x_0\)是等式的 ...