题目链接

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的更多相关文章

  1. ACM: FZU 2110 Star - 数学几何 - 水题

     FZU 2110  Star Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u  Pr ...

  2. csu 1812: 三角形和矩形 凸包

    传送门:csu 1812: 三角形和矩形 思路:首先,求出三角形的在矩形区域的顶点,矩形在三角形区域的顶点.然后求出所有的交点.这些点构成一个凸包,求凸包面积就OK了. /************** ...

  3. CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...

  4. CSU 1120 病毒(DP)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a ...

  5. CSU 1116 Kingdoms(枚举最小生成树)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1116 解题报告:一个国家有n个城市,有m条路可以修,修每条路要一定的金币,现在这个国家只 ...

  6. CSU 1113 Updating a Dictionary(map容器应用)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1113 解题报告:输入两个字符串,第一个是原来的字典,第二个是新字典,字典中的元素的格式为 ...

  7. CSU 1333 Funny Car Racing (最短路)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1333 解题报告:一个图里面有n个点和m条单向边,注意是单向边,然后每条路开a秒关闭b秒 ...

  8. CSU 1337 搞笑版费马大定理(2013湖南省程序设计竞赛J题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1337 解题报告:虽然x和y的范围都是10^8,但是如果a 是大于1000的话,那么a^3 ...

  9. CSU 1328 近似回文词(2013湖南省程序设计竞赛A题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1328 解题报告:中文题题意就不说了.还好数据不大,只有1000,枚举回文串的中心位置,然 ...

随机推荐

  1. P1316 丢瓶盖

    题目描述 陶陶是个贪玩的孩子,他在地上丢了A个瓶盖,为了简化问题,我们可以当作这A个瓶盖丢在一条直线上,现在他想从这些瓶盖里找出B个,使得距离最近的2个距离最大,他想知道,最大可以到多少呢? 输入输出 ...

  2. Spring Security 之集群Session配置

    1.   新建Maven项目 cluster-session 2.   pom.xml <project xmlns="http://maven.apache.org/POM/4.0. ...

  3. glocktop

    glocktop: Display or print active GFS2 locks. Index of glocktop man page Read glocktop man page on L ...

  4. P2096 最佳旅游线路

    最大字段和加贪心 算长了个见识吧 #include<iostream> #include<cstdio> #include<algorithm> using nam ...

  5. 泉五培训Day5

    T1 陪审团 题目 [题目描述] 陪审团制度历来是司法研究中的一个热议话题,由于陪审团的成员组成会对案件最终的结果产生巨大的影响,诉讼双方往往围绕陪审团由哪些人组成这一议题激烈争夺.小 W提出了一个甲 ...

  6. 牛客小白月赛2 D 虚虚实实 【欧拉图】【连通图】

    链接:https://www.nowcoder.com/acm/contest/86/D来源:牛客网 题目描述 震为雷,临危不乱,亨通畅达:巽为风,柔顺伸展,厚载万物. 震卦:洊雷,震,君子以恐惧修省 ...

  7. PHP开发搭建环境二:开发工具PhpStorm安装、激活以及配置

    关于php的开发工具很多,目前市面上最好用最强大的莫过于PhpStorm这款开发神器了,但是鉴于很多开发者朋友在网站上下载的PhpStorm开发工具不能用,或者使用起来很不方便,笔者把最好用的下载地址 ...

  8. P1219 N皇后

    P1219 N皇后 题目描述 检查一个如下的6 x 6的跳棋棋盘,有六个棋子被放置在棋盘上,使得每行.每列有且只有一个,每条对角线(包括两条主对角线的所有平行线)上至多有一个棋子. 上面的布局可以用序 ...

  9. 在intellij idea 里来回跳转查询方法

    在intellij idea 里来回跳转查询方法,在不知道快捷键的时候真是抓狂. 看到key map中的快捷键 后退back  ctrl +alt + ← 或者button4 click 前进forw ...

  10. Git-补丁文件交互

    版本库间的交互是通过git push和/或git pull命令实现的,这是Git最主要的交互模式,但并不是全部.使用补丁文件是另外一种交互方式,适用于参与者众多的大型项目进行分布式开发. 创建补丁 G ...