CSU-2110 Keeping Cool
题目链接
http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=2110
题目
Description
Kevin has just gotten back to his car after a morning at the beach and is about to drive away when he realises that he has left his ball somewhere. Thankfully, he remembers exactly where it is! Unfortunately for Kevin, it is extremely hot outside and any sand that is exposed to direct sunlight is very hot. Kevin’s pain tolerance allows him to only run for at most k seconds in the hot sand at one time. Kevin runs at exactly 1 metre per second on hot sand. Scattered around the beach are umbrellas. Each umbrella is a perfect circle and keeps the sand underneath it cool. Each time Kevin reaches an umbrella, he will wait there until his feet cool down enough to run for another k seconds on the hot sand. Note that Kevin will not run more than k seconds in the hot sand at one time, so if two umbrellas are more than k metres apart, Kevin will not run between them. Determine the minimum amount of time that Kevin must be in the sun in order to retrieve his ball and return back to the car.
Input
The first line of input contains four integers n (0 ≤ n ≤ 100), which is the number of umbrellas, k (1 ≤ k ≤ 100), which is the number of metres that Kevin can run on the hot sand, x (−100 ≤ x ≤ 100) and y (−100 ≤ y ≤ 100), which are the coordinates of the beach ball. Kevin starts at his car at (0; 0). You may treat Kevin and the ball as single points. The next n lines describe the umbrellas. Each of these lines contains three integers x (−100 ≤ x ≤ 100), y (−100 ≤ y ≤ 100) and r (1 ≤ r ≤ 100). The umbrella is a circle centred at (x; y) with radius r. There may be multiple items (ball, umbrella(s) or Kevin) at a single location. All measurements are in metres.
Output
Display the minimum amount of time (in seconds) that Kevin must be in the sun. If it is impossible for Kevin to get to the ball and return back to the car, display -1 instead. Your answer should have an absolute or relative error of less than 10−6.
Sample Input
0 1 0 0
0 20 1 2
0 10 20 20
2 2 7 4
6 2 2
2 2 1
1 2 3 3
0 3 2
Sample Output
0.0000000000
4.4721359550
-1
6.1289902045
4.0000000000
题意
给定n,k,x,y,n代表遮阳伞的数量,k代表kevin一次在阳光下可以呆的最长时间,在遮阳伞里呆过后就可以重置,kevin从(0,0)出发,要到(x,y)去,然后再回到(0,0),每秒kevin走1单位长度。下面n行每行给定x, y, r代表遮阳伞的坐标和半径,问kevin能否到达遮阳伞并回来,如不能则输出-1,可以则输出在阳光下呆的最小时间
题解
首先我们先跑一边dijkstra得到起点到每一个遮阳伞之间的最小距离(即在阳光下呆的最小时间和),然后我们判断在能到达的遮阳伞中有没有包含着终点的遮阳伞,有的话就可以转换为能否到这个遮阳伞,什么时候时间最小。如果没有也可以认为是坐标为(x,y) r = 0的遮阳伞。
然后我们再o(n)扫一遍看卡有没有能到这个遮阳伞的伞,有的话就把他们都记录在一个can结构体数组中,结构体记录:1.在阳光下走到终点”遮阳伞“的总时间。 2.这次到这个遮阳伞在阳光中暴露的时间。每次++cnt。之后两层循环枚举所有能到这个伞的组合,看看两次加起来在阳光中暴露的时间是否大于k,若不大于则更新答案,最后输出答案即可。
AC代码
#include<bits/stdc++.h>
#define maxn 150
#define pi pair<double, int>
using namespace std;
double d[maxn];
int n;
double k, x, y;
bool vis[maxn];
double dis(double x1, double y1, double x2, double y2) {
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
struct node {
double x, y, r;
} a[maxn];
struct can {
double c, d;
} can[maxn];
void dijkstra() {
priority_queue<pi, vector<pi>, greater<pi> > q;
fill(d + 1, d + n + 1, 0x7fffffff);
d[0] = 0.0;
fill(vis, vis + n + 1, false);
q.push(make_pair(d[0], 0));
while (!q.empty()) {
pi now = q.top(); q.pop();
int x = now.second;
if (vis[x]) continue;
vis[x] = true;
for (int i = 1; i <= n; i++) {
int v = i;
double dd = max(dis(a[x].x, a[x].y, a[i].x, a[i].y) - a[i].r - a[x].r, 0.0);
if (x != i && dd <= k) {
if (d[i] > d[x] + dd) {
d[i] = d[x] + dd;
q.push(make_pair(d[i], i));
}
}
}
}
}
int main() {
while (scanf("%d%lf%lf%lf", &n, &k, &x, &y) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%lf%lf%lf", &a[i].x, &a[i].y, &a[i].r);
}
a[0].x = a[0].y = a[0].r = 0;
dijkstra();
double min1 = 0x7fffffff;
int point = n + 1;
a[point].x = x; a[point].y = y; a[point].r = 0;
for (int i = 0; i <= n; i++) {
if (dis(a[i].x, a[i].y, x, y) - a[i].r <= 0 && d[i] < min1) {
point = i;
min1 = d[i];
}
}
double ans = 0x7fffffff;
int cnt = 0;
for (int i = 0; i <= n; i++) {
double dd = max(dis(a[i].x, a[i].y, a[point].x, a[point].y) - a[i].r - a[point].r, 0.0);
if (dd <= k) {
can[++cnt].c = dd;
can[cnt].d = d[i] + dd;
}
}
for (int i = 1; i <= cnt; i++) {
for (int j = 1; j <= cnt; j++) {
if (can[i].c + can[j].c <= k) {
ans = min(ans, can[i].d + can[j].d);
}
}
}
if (ans != 0x7fffffff) printf("%.10lf\n", ans);
else printf("-1\n");
}
return 0;
}
/**********************************************************************
Problem: 2110
User: Artoriax
Language: C++
Result: AC
Time:4 ms
Memory:2044 kb
**********************************************************************/
CSU-2110 Keeping Cool的更多相关文章
- ACM: FZU 2110 Star - 数学几何 - 水题
FZU 2110 Star Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Pr ...
- csu 1812: 三角形和矩形 凸包
传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...
- CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...
- CSU 1120 病毒(DP)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...
- CSU 1116 Kingdoms(枚举最小生成树)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...
- CSU 1113 Updating a Dictionary(map容器应用)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...
- CSU 1333 Funny Car Racing (最短路)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒 ...
- CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 解题报告:虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3 ...
- CSU 1328 近似回文词(2013湖南省程序设计竞赛A题)
题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 解题报告:中文题题意就不说了.还好数据不大,只有1000,枚举回文串的中心位置,然 ...
随机推荐
- xrdp 安装后 WINDOWS远程登录出错
xrdp需要vnc作为基础服务, sudo apt-get install tightvncserver 树莓派上这个命令运行下再连就好了
- 关于win10深度学习安装配置 CUDA9.0+VS2017+Cudnn7.4.1.5+Anaconda3(cupy安装包)+python3.7+pycharm
0 查看电脑系统版本(非常重要) WIN+R->输入winver, 系统版本号必须高于1703,否则CUDA9.0难以运行!!!! 1 安装 NVIDIA 显卡驱动程序 下载地址:驱动程序 选择 ...
- 前端css盒模型及标准文档流及浮动问题
1.盒模型 "box model"这一术语是用来设计和布局时使用,然后在网页中基本上都会显示一些方方正正的盒子.我们称为这种盒子叫盒模型. 盒模型有两种:标准模型和IE模型.这里重 ...
- 分页查询关键代码 多条件查询关键代码 删除选中商品关键代码 修改要先回显再修改 修改要先回显再修改 同一业务集中使用同一servlet的方法
分页查询关键代码: 通过servlet转发回来的各种信息进行分页的设计(转发回的信息有 分页查询的List集合 查询的页码 查询的条数 查询的数据库总条数 查询的总页码) 从开始时循环10次出现十个数 ...
- 使用winsw将spring-boot jar包注册成windows服务
背景:最近的项目中使用spring-boot, https://github.com/kohsuke/winsw/releases <service> <id>YJPSS< ...
- Intellij IDEA 查找接口实现类的快捷键
查找接口的实现类: IDEA 风格 ctrl + alt +B 查看类或接口的继承关系: ctrl + h 1.IDEA_查找接口的实现 的快捷键 http://blog.csdn.net/u0100 ...
- JAVA / MySql 编程——第六章 Mysql 创建账户的相关命令
1. 创建普通用户: 语法: CREATE USER `user`@`host` [IDENTIFIED 'password']; //user:用户名,host:主机名,passw ...
- IntelliJ IDEA 12 创建Web项目 教程 超详细版【转】
IntelliJ IDEA 12 新版本发布 第一时间去官网看了下 黑色的主题 很给力 大体使用了下 对于一开始就是用eclipse的童鞋们 估计很难从eclipse中走出来 当然 我也很艰难的走 ...
- 列表,元组的操作,for循环
1.列表 # li = ["wang","jian","wei"] # print(li) # 结果:['wang', 'jian', 'w ...
- JavaSE 第二次学习随笔(String的坑 + ==)
String 类是一个final类, 其内部是使用的 private final char value[]; 来存储内容, 其既可以当作一个基本类型来使用也可以当作一个类来使用;final 类(Str ...