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. 杀死O2O的三大杀手?!

    0个O2O领域,20多个“已故”项目,三种不同的死因……记者糜丰.孙锋将O2O项目的一些固有问题分析得淋漓尽致! 这三个O2O杀手分别是:买不起的流量.承担不起的物流成本.惹不起的传统企业. 除了找钱 ...

  2. Road to the future——伪MVVM库Q.js

    模仿Vuejs的伪MVVM库,下面是使用说明 项目地址:https://github.com/miniflycn/Q.js 相关项目:https://github.com/miniflycn/Ques ...

  3. OAuth介绍

    1.认识OAUTH OAUTH协议为用户资源的授权提供了一个安全的.开放而又简易的标准.与以往的授权方式不同之处是OAUTH的授权不会使第三方触及到用户的帐号信息 (如用户名与密码),即第三方无需使用 ...

  4. volley中网络请求

    首先使用Volley类创建 RequestQueue queue = Volley.newRequestQueue(this);  Making GET Requests final String u ...

  5. Invalid Image Path - No image found at the path referenced under key "CFBundleIconFile": Icon.png

    I got the same error when uploading my app. Moving all icon files to the Asset Catalog works if your ...

  6. Microsoft 2013 新技术学习笔记 三

    什么是代码结构的组织?asp.net MVC 5 默认创建出的几个目录的标准含义分别如下: Controllers目录存放MVC模式中的Controler Models目录存放MVC模式中的Model ...

  7. SQL Server2008如何设置开启远程连接

    登陆SQL Server 2008(windows身份认证),登陆后右击,选择“属性”. 2 左侧选择“安全性”,选中右侧的“SQL Server 和 Windows 身份验证模式”以启用混合登录模式 ...

  8. 分享一个Mongodb PHP封装类

    <?php /** * Mongodb 基本操作API,支持基本类似关系统型数据库的操作接口 * * @version 1.0 * [说明] * * 1:该版本API实现了 Mongodb 中最 ...

  9. CyanogenMod wiki reading tips | Android tips

    To Enable the Developer and Performance settings on CyanogenMod 10.1 In the Settings app, choose the ...

  10. 字体文件放入CDN服务器中,跨域问题(IIS版)

    Font from origin 'http:/XXXX' has been blocked from loading by Cross-Origin Resource Sharing policy: ...