三分 --- CSU 1548: Design road
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的更多相关文章
- CSU 1548 Design road(三分查找)
题目链接:https://cn.vjudge.net/problem/142542/origin Description You need to design road from (0, 0) to ...
- 1548: Design road (思维题 做法:三分找极值)
1548: Design road Submit Page Summary Time Limit: 2 Sec Memory Limit: 256 Mb Submitted ...
- csu 1548(三分)
1548: Design road Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 383 Solved: 200[Submit][Status][We ...
- Contest2071 - 湖南多校对抗赛(2015.03.28)
Contest2071 - 湖南多校对抗赛(2015.03.28) 本次比赛试题由湖南大学ACM校队原创 http://acm.csu.edu.cn/OnlineJudge/contest.php?c ...
- csu 1947 三分
题意: 长者对小明施加了膜法,使得小明每天起床就像马丁的早晨一样. 今天小明早上6点40醒来后发现自己变成了一名高中生,这时马上就要做早操了,小明连忙爬起来 他看到操场密密麻麻的人,突然灵光一闪想到了 ...
- Design and Analysis of Algorithms_Brute Froce
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...
- (转)The Road to TensorFlow
Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a ...
- 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 ...
- 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 ...
随机推荐
- .Net规则引擎介绍 - REngine
规则引擎 规则引擎由推理引擎发展而来,是一种嵌入在应用程序中的组件,实现了将业务决策从应用程序代码中分离出来,并使用预定义的语义模块编写业务决策.接受数据输入,解释业务规则,并根据业务规则做出业务决策 ...
- android:style.xml
<?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2006 The Andr ...
- Chapter 5. Graph Theory:: Fundamentals:: Intermediate
10457 - Magic Car 题意一开始看起来有点费解,其实最后就是要起点到终点的路径上最大边与最小边之差越小越好.这样我们可以先将边排个序,然后枚举路径上的最小边,之后依次将比它大的边按升序的 ...
- 每日英语:Mistrust Between U.S., Malaysia Strains Probe
Mistrust between U.S. and Malaysian air-accident investigators has hampered a multinational probe in ...
- Transaction recovery: lock conflict caught and ignored
Transaction recovery: lock conflict caught and ignored环境:RAC 4节点.oracle 11.2.0.4.redhat 5.9 64bit 问题 ...
- web项目总结
web项目 Webroot下面的index.jsp页面的内容: <%@ page language="java" pageEncoding="UTF-8" ...
- 查看SqlAzure和SQLServer中的每个表数据行数
SqlAzure中的方式: select t.name ,s.row_count from sys.tables t join sys.dm_db_partition_stats s ON t.obj ...
- iOS 内存管理机制和循环引用处理方法
简述 ARC: 自动引用计数, Automatic Reference Counting MRC: Mannul Reference Counting ARC工作原理 1.当每次创建一个新实例时,AR ...
- 哈希表用于Key与Value的对应
一个类的某个属性要实现Key与Value的对应,以便通过访问名称就可以知道对应值,而不是通过索引号,最简单的方法直接用 哈希表using System.Collections;class Class1 ...
- android 模拟器
参考:http://www.syscs.com/node/504 --skin WVGA800 - -no-boot-anim -wipe-: the dpi for the device you a ...