1665: [Usaco2006 Open]The Climbing Wall 攀岩

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 407  Solved: 219
[Submit][Status][Discuss]

Description

One of the most popular attractions at the county fair is the climbing wall. Bessie wants to plan her trip up the wall in advance and needs your help. The wall is 30,000 millimeters wide and H (1001 <= H <= 30,000) millimeters high and has F (1 <= F <= 10,000) hoof-holds at unique X,Y coordinates expressed in millimeters. 0,0 is at the ground level on the left side of the wall. Hoof-holds are separated by at least 300 millimeters since no cow can maneuver them if they are spaced too close! Bessie knows there is at least one way up. Bessie, through techniques only she knows, uses successive single hoof-holds to climb the wall. She can only move from one hoof-hold to another if they are no more than one meter apart. She can, of course, move up, down, right, left or some combination of these in each move. Similarly, once she gets to a hoof-hold that is at least H-1000 millimeters above the ground, she can nimbly climb from there onto the platform atop the wall. Bessie can start at any X location that has a Y location <= 1000 millimeters. Given the height of the wall and the locations of the hoof-holds, determine the smallest number of hoof-holds Bessie should use to reach the top.

Bessie参加了爬墙比赛,比赛用的墙宽30000,高H(1001 <= H <= 30,000)。墙上有F(1 <= F <= 10,000)个不同的落脚点(X,Y)。 (0,0)在左下角的地面。所有的落脚点至少相距300。Bessie知道至少有一条路可以上去。 Bessie只能从一个落脚点爬到另一个距离不超过1000的落脚点,她可以向上下左右四个方向爬行。同样地,一旦她到达了一个高度 至少有H-1000的落脚点,她可以敏捷地爬到墙顶上。Bessie一开始可以在任意一个高度不超过1000的落脚点上。问Bessie至少攀爬多少次.这里两个点的距离都是欧几里得距离

Input

* Line 1: Two space-separated integers, H and F.

* Lines 2..F+1: Each line contains two space-separated integers (respectively X and Y) that describe a hoof-hold. X is the distance from the left edge of the climbing wall; Y is the distance from the ground.

Output

* Line 1: A single integer that is the smallest number of hoof-holds Bessie must use to reach the top of the climbing wall.

Sample Input

3000 5
600 800
1600 1800
100 1300
300 2100
1600 2300

INPUT DETAILS:

The wall is three meters high with 5 hoof-holds.

Sample Output

3

HINT

分别经过(600,800), (100,1300), (300,2100)

Source

Silver

依据条件建图,然后跑出最短路即可

可能会卡spfa,我没有试,我的正确率已经惨不忍睹了,权限狗的悲哀 用dijkstra

#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int read(){int x=0;int f=1;char ch=getchar();while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}return x*f;
}
const int MAXN=1e6+10;
struct node{int y,next;
}e[MAXN];
struct hh{int x,y;
}k[MAXN];
int linkk[MAXN],len=0,h,n,dis[MAXN],vis[MAXN];
typedef pair <int,int> pii;
priority_queue < pii,vector<pii>,greater<pii> > q;
inline void insert(int xx,int yy){e[++len].y=yy;e[len].next=linkk[xx];linkk[xx]=len;
}
namespace zhangenming{void dijsktra(){q.push(make_pair(0,n+1));memset(dis,127,sizeof(dis));dis[n+1]=0;while(!q.empty()){int tn=q.top().second;q.pop();if(vis[tn])  continue;vis[tn]=1;for(int i=linkk[tn];i;i=e[i].next){if(dis[tn]+1<dis[e[i].y]){dis[e[i].y]=dis[tn]+1;q.push(make_pair(dis[e[i].y],e[i].y));}}}}void init(){h=read();n=read();for(int i=1;i<=n;i++){k[i].x=read();k[i].y=read();}for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){if((k[i].x-k[j].x)*(k[i].x-k[j].x)+(k[i].y-k[j].y)*(k[i].y-k[j].y)<=1000000) insert(i,j),insert(j,i);}if(k[i].y<=1000) insert(n+1,i);if(k[i].y>=h-1000) insert(i,n+2);}dijsktra();cout<<dis[n+2]-1<<endl;}
}
int main(){using namespace zhangenming;init();return 0;
}

  

转载于:https://www.cnblogs.com/something-for-nothing/p/8031090.html

BZOJ1665 Usaco2006 Open The Climbing Wall相关推荐

  1. bzoj 1665: [Usaco2006 Open]The Climbing Wall 攀岩(最短路)

    1665: [Usaco2006 Open]The Climbing Wall 攀岩 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 378  Solve ...

  2. 【BZOJ】1665: [Usaco2006 Open]The Climbing Wall 攀岩(spfa)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1665 这题只要注意到"所有的落脚点至少相距300"就可以大胆的暴力了. 对于每个 ...

  3. 【PyTorch】8 语言翻译Torchtext实战——英语和德语翻译、Attention模型、 Pytorch 1.8 安装

    torchtext 语言翻译 1. 数据处理 2. DataLoader 3. 定义nn.Module和Optimizer 4. 训练 4.1 Pytorch 1.8 安装 4.2 训练网络 5. 测 ...

  4. Java解惑 电子书

    --表达式谜题 Java 谜题 1--表达式谜题 谜题 1:奇数性 下面的方法意图确定它那唯一的参数是否是一个奇数.这个方法能够正确运转 吗? public static boolean isOdd( ...

  5. 【POJ1113】Wall(凸包)

    [题目] Description Once upon a time there was a greedy King who ordered his chief Architect to build a ...

  6. LeetCode 746. Min Cost Climbing Stairs--动态规划--Java,C++,Python解法

    题目地址:Min Cost Climbing Stairs - LeetCode LeetCode 动态规划(Dynamic programming)系列题目:LeetCode 动态规划(Dynami ...

  7. LetCode 70. Climbing Stairs--动态规划-爬梯子--递归等解法

    LeetCode 动态规划(Dynamic programming)系列题目:LeetCode 动态规划(Dynamic programming)系列题目 You are climbing a sta ...

  8. gcc 常用命令-Wall

    -Wall GCC还有一些其它编译选项也能够产生有用的警告信息.这些选项大多以-W开头,其中最有价值的当数-Wall了,使用它能够使GCC产生尽可能多的警告信息. 转载于:https://www.cn ...

  9. ZOJ 2747 Paint the Wall(离散化+暴力)题解

    题意:给你一个面,然后涂颜色,问你最后剩多少颜色,每种颜色面积. 思路:第一反应是二维线段树,代码又臭又长,可以做.但是这题暴力+离散化就可以过.可以看到他给的n只有100,也就是说最坏情况下会涂10 ...

最新文章

  1. springcloud基于ribbon的canary路由方案
  2. 多少人没熬过45-55这段危险期? 为家人, 请多看一眼!
  3. 可视化Spring开发插件 Spring IDE
  4. 影响网站快照异常的因素有哪些?
  5. k8s traefik ingress tls
  6. Linux服务器编程之:chown()函数,chown命令
  7. Android开发之ANR原因分析
  8. 36 张图梳理 Intellij IDEA 常用设置,太全了值得收藏!
  9. 产品经理经验谈100篇(一)-一个经销商订单贷的业务设计
  10. 机器学习算法总结--K近邻
  11. 这篇被引用近4k次的论文教你如何正确的理解和使用相关系数!
  12. bigint最大有多少位_《追光吧哥哥》21位艺人靠实力成团?不见得,节目赛制本不公平...
  13. Uber首位App开发者离职自述:我们如何从3人小作坊变成大公司
  14. python能做什么程序-python能做哪些生活有趣的事情
  15. vc++开发学习二(模态对话框和非模态对话框的创建和销毁)
  16. atom 基础使用教程
  17. Linux下安装、配置、授权、调优Mysql
  18. 《工业设计史》第十章:战后重建与设计
  19. 计算机主板USB接口介绍,如何解决计算机主板USB接口供电不足
  20. 右键菜单项删除 pycharm vs

热门文章

  1. Illegal character in authority at index 18:
  2. 拼多多API接口,item_search - 按关键字搜索商品
  3. Dota2 AI 开发 (二)定制AI阵容 配置英雄出装
  4. Web前端:2022年最佳Javascript动画库
  5. 【uniapp】 读取手机通讯录权限
  6. 谭浩强《C语言》学习1
  7. Poi导出excel文件提示由于一些内容不可读取,Excel无法打开
  8. 数据可视化项目学习思维导图
  9. Redis应用项目---抢红包功能(二)
  10. 【附源码】计算机毕业设计SSM网上旅游订票服务系统