牛客 国庆七天乐 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处理有多少位置符合 ...
随机推荐
- 在WPF中自定义控件(3) CustomControl (上)
原文:在WPF中自定义控件(3) CustomControl (上) 在WPF中自定义控件(3) CustomControl (上) 周银辉 ...
- 炒鸡简单的javaScript的call和apply方法
解释一 作者:杨志 链接:https://www.zhihu.com/question/20289071/answer/14644278 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商 ...
- 1321. [ZJOI2012] 灾难
1321. [ZJOI2012] 灾难 ★★☆ 输入文件:catas.in 输出文件:catas.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 阿米巴是小强的 ...
- pxe无人值守安装linux机器笔记----摘抄
1. 基建工作 1.关闭防火墙 a)service iptables stop b)service ip6tables stop c)chkconfig iptables off d)chkconfi ...
- FRDM-KL25Z开发板上电试用
1. 硬件平台:FRDM-KL25Z开发板,先看下板子,Cortex M0+的内核,板子上自带MMA8451Q的三轴加速度传感器,触摸滑动按键,openSDA调试器.MCU主频48MHz,有16KB ...
- Android之线程安全的单例模式,Adapter注意事项之引用传值
线程安全的单例模式单位模式一般写法如下: public static FestivalLab mInstance; private FestivalLab() { } public static Fe ...
- React开发时候注意点
JSX 使用jsx的使用,用一个{}包裹起来,例如 const method = {<div> 123 </div>} 使用()小括号,防止分号自动插入 const eleme ...
- NOI中“大整数加法”问题不能AC的解决建议
一.检查输入000和00相加是否出结果. 二.数组不要开小了,亲测256的数组不够.推荐1024. 附录AC程序: 如果不能AC请将256改为1024,255改为1023. #include &l ...
- python接口测试(三)——Excell文件读取进行参数化
python进行http请求时,需要对参数进行参数化,此时就可以运用Excel进行,具体如下: 1.梳理出请求中那些参数需要参数化,然后新建一个Excel,如图: 2.读取Excel中的内容,在读取前 ...
- zabbix 通过key(键值)获取信息
在agent端进行修改264行,例如: UserParameter=get.os.type,head -1 /etc/issue 保存重启agent 验证 zabbix_get -s IP -k ge ...