bzoj4152: [AMPPZ2014]The Captain
水。。。
这个建边排序一下从一边连向一边
dij在这种稀疏图果然不够优秀啊。只是学了一发。
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> using namespace std;struct node {int x,y,d,next; }a[810000];int len,last[210000]; void ins(int x,int y,int d) {len++;a[len].x=x;a[len].y=y;a[len].d=d;a[len].next=last[x];last[x]=len; }struct point {int x,y,id; }p[210000]; bool cmp1(point p1,point p2){return p1.x<p2.x;} bool cmp2(point p1,point p2){return p1.y<p2.y;}int d[210000]; struct dij {int x;friend bool operator <(dij n1,dij n2){return d[n1.x]>d[n2.x];} };priority_queue<dij>q; bool v[210000];int main() {int n;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y),p[i].id=i;len=0;memset(last,0,sizeof(last));sort(p+1,p+n+1,cmp1);for(int i=1;i<n;i++)ins(p[i].id,p[i+1].id,p[i+1].x-p[i].x),ins(p[i+1].id,p[i].id,p[i+1].x-p[i].x);sort(p+1,p+n+1,cmp2);for(int i=1;i<n;i++)ins(p[i].id,p[i+1].id,p[i+1].y-p[i].y),ins(p[i+1].id,p[i].id,p[i+1].y-p[i].y);memset(d,63,sizeof(d));d[1]=0;memset(v,false,sizeof(v));v[1]=true;dij tt;tt.x=1;q.push(tt);while(q.empty()==false){int x=q.top().x;q.pop();for(int k=last[x];k;k=a[k].next){int y=a[k].y;if(d[y]>d[x]+a[k].d){d[y]=d[x]+a[k].d;if(v[y]==false){v[y]=true;tt.x=y;q.push(tt);}}}v[x]=false;}printf("%d\n",d[n]);return 0; }
转载于:https://www.cnblogs.com/AKCqhzdy/p/8858123.html
bzoj4152: [AMPPZ2014]The Captain相关推荐
- BZOJ4152 AMPPZ2014 The Captain(最短路)
事实上每次走到横坐标或纵坐标最接近的点一定可以取得最优方案.于是这样连边跑最短路就可以了. #include<iostream> #include<cstdio> #inclu ...
- bzoj4152 [AMPPZ2014]The Captain
Description 给定平面上的 \(n\) 个点,定义 \((x_1,y_1)\) 到 \((x_2,y_2)\) 的费用为 \(\min(|x_1-x_2|,|y_1-y_2|)\) ,求从 ...
- 4152. [AMPPZ2014]The Captain(稠密图最短路)
4152. [AMPPZ2014]The Captain 显然稠密图的边数时n2n^2n2量级,我们不可能把所有边建立出来,这时候通常寻求一些性质详细见[论题选编]稠密图最短路 针对本题我们可以先这样 ...
- 【BZOJ】4152: [AMPPZ2014]The Captain【SLF优化Spfa】
4152: [AMPPZ2014]The Captain Time Limit: 20 Sec Memory Limit: 256 MB Submit: 2107 Solved: 820 [Sub ...
- BZOJ 4152: [AMPPZ2014]The Captain(最短路)
Time Limit: 20 Sec Memory Limit: 256 MB Submit: 1550 Solved: 619 [Submit][Status][Discuss] Descrip ...
- 2019.4.summary
2019.4.1 BZOJ1061: [Noi2008]志愿者招募 真心有点难QAQ https://www.byvoid.com/zhs/blog/noi-2008-employee 看void爷的 ...
- python画热力图_Python中绘制场景热力图
原博文 2019-08-06 15:39 − 我们在做诸如人群密集度等可视化的时候,可能会考虑使用热力图,在Python中能很方便地绘制热力图. 下面以识别图片中的行人,并绘制热力图为例进行讲解. 步 ...
- 一句话题解(20170801~20170125)
8.1 bzoj 4720 noip2016 换教室 floyd预处理+期望(薛定谔的猫) bzoj 4318 OSU! 三次函数期望值 从一次.二次推得 8.2 bzoj 1076 状压+期望DP ...
- bzoj4152 The Captain (dijkstra)
做dijkstra,但只需要贪心地把每个点连到它左边.右边.上边.下面的第一个点就可以了 1 #include<bits/stdc++.h> 2 #define pa pair<in ...
最新文章
- AI视频行为分析系统项目复盘——技术篇4:deepsort原理图
- git推送密码_保护代码完整性(六):在 Git 上使用 PGP
- python中的 and以及or
- nmmqq.php?/lspc.html,html中的图片直接使用base64编码后的字符串代替详解
- 用友仓库档案boot直接访问html,图文解析用友仓库软件怎样设置档案?
- c#中的ref、out、params参数
- “阿里云开放平台俱乐部”首站启航
- Zabbix全网监控
- SHT30温湿度传感器使用记录(AVR atmega128)
- iOS 5 故事板进阶(3)
- 砥砺前行,匠心致远|袋鼠云联合创始人、易知微CEO宁海元荣获“数字工匠 ”
- C++入门:构造函数,析构函数,拷贝构造函数,运算符重载详解
- 开发小程序以及后台管理系统攥淘宝佣金
- 2023年贵州省职业技能大赛“网络安全” 项目比赛任务书
- 关于樱桃键盘锁定alt键和win键这件事
- 电子元器件篇—三极管
- has no exported member
- 2020年计算机网络管理员赛项竞赛试题(5)
- c语言时钟程序整点报时,C语言 · 报时助手(示例代码)
- php加解密工具php_screw-1.5_php5.3支持php5.3以上版本
热门文章
- 基于django rest framework的mock server实践
- Codeforces 999F Cards and Joy 【dp】【性质】
- AFNetworking到底做了什么?
- 实验二+140+阮晨曦
- WinForm - 两个窗体之间的方法调用
- 深刻理解Servlet运行机制和生命周期
- css3 animation 动画属性简介
- 批量提交 kafka_Kafka精华问答|kafka的使用场景是什么?
- java中的方法在哪里_Java中的本机方法是什么,应在哪里使用?
- Shell else if mysql_Shell if else语句(详解版)