牛客 国庆七天乐 day1 L
https://www.nowcoder.com/acm/contest/201/L
题意:给你两条平行的直线和n个圆,在直线上面行走和在圆上和在圆内行走不需要耗费体力,除了这些区域外平面上经过任意两点需要走的距离都是欧几里得距离,求从直线1走到直线2所需要消耗的最小体力是多少。
题解:一开始以为是计算几何,但是冷静分析了一波后发现这个题要用最短路写,建边过程有点复杂:
1.从直线1到直线2要建边。
2.有n<1000个点,每个圆之间都应该有边,所以n方将所有圆连接起来,记得在圆内走和在圆上走不消耗体力需要处理一下。
3.从直线1到每个圆需要建边,从直线2到每个圆需要建边。
tips:最后建边的条数为2*(n*n+2*n+2)条,所以要把存边的数组开到1e6
建边完成后就简单的跑最短路就好,记得所有变量都要用double不容易出错
代码如下:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
#define PI acos(-1)
#define eps 1e-8
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
//#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int maxn = 1e6+;
const int inf = 2.1e9;
const LL INF = ;
const int MOD = 1e9+;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
double dpow(double a,LL b){double ans=1.0;while(b){if(b%)ans=ans*a;a=a*a;b/=;}return ans;}
int n;
struct point{
int x,y;
int r;
double d1,d2;
}p[maxn];
double Dis(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double dis1(int a,int b,int c1,int c2){
return abs(c1-c2)/sqrt(a*a+b*b);
}
double dis2(int a,int b,int c,int x,int y){
return abs(a*x+b*y+c)/sqrt(a*a+b*b);
}
struct node{
int v,nxt;
double w;
bool operator<(const node p)const{return p.w<w;}
}edge[maxn];
int head[maxn];
int tot;
void add(int u,int v,double w){
edge[tot].v=v;
edge[tot].w=w;
edge[tot].nxt=head[u];
head[u]=tot++;
}
double dis[maxn];
bool vis[maxn];
void dij(){
fill(dis+, dis + n+, inf);
dis[n+]=;
priority_queue<node>q;
node tmp;
tmp.v=n+;
tmp.w=;
q.push(tmp);
while(!q.empty()){
tmp=q.top();
q.pop();
if(!vis[tmp.v]){
vis[tmp.v]=;
int u=tmp.v;
for(int i=head[u];i!=-;i=edge[i].nxt){
int v=edge[i].v;
if(dis[v]>dis[u]+edge[i].w){
dis[v]=dis[u]+edge[i].w;
tmp.w=dis[v];
tmp.v=v;
q.push(tmp);
}
}
}
}
}
int main(){
#ifndef ONLINE_JUDGE
FIN
#endif
int a,b,c1,c2;
cin>>n>>a>>b>>c1>>c2;
int ans=dis1(a,b,c1,c2);
// fuck(ans);
memset(head,-,sizeof(head));
tot=;
add(n+,n+,ans);
add(n+,n+,ans);
for(int i=;i<=n;i++){
scanf("%d%d%d",&p[i].x,&p[i].y,&p[i].r);
p[i].d1=max(0.0,dis2(a,b,c1,p[i].x,p[i].y)-p[i].r);
add(n+,i,p[i].d1);
add(i,n+,p[i].d1);
p[i].d2=max(0.0,dis2(a,b,c2,p[i].x,p[i].y)-p[i].r);
add(n+,i,p[i].d2);
add(i,n+,p[i].d2);
}
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
double d=Dis(p[i],p[j]);
d=max(0.0,d-p[i].r-p[j].r);
// fuck(d);
add(i,j,d);
add(j,i,d);
}
}
dij();
// for(int i=0;i<n+3;i++){
// printf("%10.6f\n",dis[i]);
// }
printf("%.6f\n",dis[n+]);
}
牛客 国庆七天乐 day1 L的更多相关文章
- 牛客国庆集训派对Day1 L New Game!(堆优化dijkstra+建图)
链接:https://ac.nowcoder.com/acm/contest/201/L来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言2097 ...
- 牛客国庆集训派对Day1 L-New Game!(最短路)
链接:https://www.nowcoder.com/acm/contest/201/L 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...
- 2019牛客国庆集训派对day1(A, B E F K)
链接:https://ac.nowcoder.com/acm/contest/1099#question A:可知符合条件的图中间肯定存在一个由1构成的矩形,找到由1构成矩形的边界,判断出现的1的数量 ...
- 牛客国庆集训派对Day1 Solution
A Tobaku Mokushiroku Kaiji 水. #include <bits/stdc++.h> using namespace std; ], b[]; void Ru ...
- 牛客国庆集训派对Day1:J:Princess Principal(栈模拟求括号匹配)
题目描述 阿尔比恩王国(the Albion Kingdom)潜伏着一群代号“白鸽队(Team White Pigeon)”的间谍.在没有任务的时候,她们会进行各种各样的训练,比如快速判断一个文档有没 ...
- 2019牛客国庆集训派对day1 K题 双向链表练习题 splay区间翻转
题目链接: 解法: 先建n颗平衡树,合并的时候将a中最右的结点翻转到根节点,b中最左的结点翻转到根节点,对合并后的根节点进行标记. #include <bits/stdc++.h> usi ...
- 牛客国庆集训派对Day1.B.Attack on Titan(思路 最短路Dijkstra)
题目链接 \(Description\) 给定\(n,m,C\)及大小为\((n+1)(m+1)\)的矩阵\(c[i][j]\).平面上有\((n+1)(m+1)\)个点,从\((0,0)\)编号到\ ...
- 牛客国庆集训派对Day1 B. Attack on Titan
B. Attack on Titan 链接 #include<cstdio> #include<algorithm> #include<cstring> #incl ...
- 2019牛客国庆集训派对day1
C 存每个值存在的位置,枚举末尾的值,再枚举前面的值,哈希二分出最长相同的,即剩下的为不同的 D \(f_{i,j,k}\)为前i位,最后一个3因子在j,次因子在k G bitset处理有多少位置符合 ...
随机推荐
- xshell怎样打印
Xshell提供用本地打印机打印终端窗口文本的功能.在Xshell打印时可以沿用终端窗口使用的字体及颜色.且在页面设置对话框可以设置打印纸的边距. 如何设置打印纸的大小和方向: 1.打开xshell ...
- 谷歌面试官经典作品(CTCI)目录
1.1 判断一个字符串中的字符是否唯一 1.2 字符串翻转 1.3 去除字符串中重复字符 1.8 利用已知函数判断字符串是否为另一字符串的子串 2.1 从链表中移除重复结点 2.2 实现一个算法从一个 ...
- RHCE7认证学习笔记17——KickStart安装系统
一.自动化安装系统工具 1.Cobbler 另一个自动化安装工具: 2.Kickstart 二.使用kickstart自动化安装系统 服务器安装的软件: 1.dhcp服务 [root@lin ...
- IDLE激活方法
激活流程 一.通过Activation code 方式激活, 注册码获取地址为:http://idea.lanyus.com/ 在idea或者pycharm的Activation code中输入 注册 ...
- ora-12154 TNS:"无法处理服务名"的一个解决方法
http://www.cnblogs.com/xh3/archive/2007/04/21/722217.html 很怪异的一个问题,在网络环境下配置客户端,竟然怎么也连不上主机了,看了不少帖子,大多 ...
- Spring MVC - URL路径映射
1. 普通映射 A. @RequestMapping("/test1") B. @RequestMapping(value={"/test1", "/ ...
- android中的AIDL学习笔记
一.定义 AIDL是用来解决进程间通信的(一般有四种方式:Activity.Service.ContentProvider.Broadcast Receiver),两个进程间无法直接通信,所以要用AI ...
- cmd命令笔记
查看端口信息:netstat -ano eg. netstat -ano|findstr 0.0.0.0:443 根据pid查看进程信息等:wmic process get name,executab ...
- deeplearning.ai课程学习(4)
第四周:深层神经网络(Deep Neural Networks) 1.深层神经网络(Deep L-layer neural network) 在打算使用深层神经网络之前,先去尝试逻辑回归,尝试一层然后 ...
- 使用SetOperations(无序)操作redis
方法 c参数 s说明 Long add(K key, V... values); K key:集合key V... values:key对应的值 向集合中添加一个或多一个元素 Long remove( ...