BZOJ 1665: [Usaco2006 Open]The Climbing Wall 攀岩
题目
1665: [Usaco2006 Open]The Climbing Wall 攀岩
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 197 Solved: 95
[Submit][Status]
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
600 800
1600 1800
100 1300
300 2100
1600 2300
INPUT DETAILS:
The wall is three meters high with 5 hoof-holds.
Sample Output
HINT
题解
处理点的关系,最短路跑一遍!
代码
/*Author:WNJXYK*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<map>
using namespace std; #define LL long long
#define Inf 2147483647
#define InfL 10000000000LL inline int abs(int x){if (x<) return -x;return x;}
inline int abs(LL x){if (x<) return -x;return x;}
inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
inline int remin(int a,int b){if (a<b) return a;return b;}
inline int remax(int a,int b){if (a>b) return a;return b;}
inline LL remin(LL a,LL b){if (a<b) return a;return b;}
inline LL remax(LL a,LL b){if (a>b) return a;return b;}
inline void read(int &x){x=;int f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}x=x*f;}
inline void read(LL &x){x=;LL f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}x=x*f;}
inline void read(int &x,int &y){read(x);read(y);}
inline void read(LL &x,LL &y){read(x);read(y);}
inline void read(int &x,int &y,int &z){read(x,y);read(z);}
inline void read(int &x,int &y,int &n,int &m){read(x,y);read(n,m);}
inline void read(LL &x,LL &y,LL &z){read(x,y);read(z);}
inline void read(LL &x,LL &y,LL &n,LL &m){read(x,y);read(n,m);} const int Maxf=;
struct Node{
int x,y;
};
Node p[Maxf+];
int h,f; struct Edge{
int v;
int dist;
int nxt;
Edge(){}
Edge(int a,int b,int c){v=a;dist=b;nxt=c;}
};
const int Maxn=;
Edge e[Maxn+];
int head[Maxf+];
int nume;
inline void addEdge(int x,int y,int dist){
e[++nume]=Edge(y,dist,head[x]);
head[x]=nume;
e[++nume]=Edge(x,dist,head[y]);
head[y]=nume;
}
inline int getDist(Node a,Node b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
const int mDist=; queue<int> que;
bitset<Maxf+> inque;
int dist[Maxf+];
inline void SPFA(int src){
inque.reset();
memset(dist,,sizeof(dist));
que.push(src);
inque[src]=true;
dist[src]=;
while(!que.empty()){
int now=que.front();
que.pop();
for (int i=head[now];i;i=e[i].nxt){
int v=e[i].v;
int w=e[i].dist;
if (dist[v]>dist[now]+w){
dist[v]=dist[now]+w;
if (inque[v]==false){
inque[v]=true;
que.push(v);
}
}
}
inque[now]=false;
} } int main(){
read(h,f);
for (int i=;i<=f;i++) read(p[i].x,p[i].y);
for (int i=;i<f;i++){
for (int j=i+;j<=f;j++){
int tDist=getDist(p[i],p[j]);
if (tDist<=mDist){
addEdge(i+,j+,);
//cout<<i<<" "<<j<<endl;
}
}
} //cout<<nume<<endl;
for (int i=;i<=f;i++){
if (h-<=p[i].y){
addEdge(,i+,);
//cout<<0<<" "<<i<<endl;
}
if (p[i].y<=){
addEdge(i+,f+,);
//cout<<i<<" "<<f+1<<endl;
}
} SPFA(); cout<<dist[f+]+<<endl; return ;
}
BZOJ 1665: [Usaco2006 Open]The Climbing Wall 攀岩的更多相关文章
- 【BZOJ】1665: [Usaco2006 Open]The Climbing Wall 攀岩(spfa)
http://www.lydsy.com/JudgeOnline/problem.php?id=1665 这题只要注意到“所有的落脚点至少相距300”就可以大胆的暴力了. 对于每个点,我们枚举比他的x ...
- [Usaco2006 Open]The Climbing Wall 攀岩
Description One of the most popular attractions at the county fair is the climbing wall. Bessie want ...
- BZOJ1665 : [Usaco2006 Open]The Climbing Wall 攀岩
直接BFS貌似复杂度飞起来了,于是我们用k-d tree优化找点的过程即可.时间复杂度$O(n\sqrt{n})$. #include<cstdio> #include<algori ...
- BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]
1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1017 Solved: ...
- BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节
Description Input * Line 1: 牛的数量 N. * Lines 2..N+1: 第 i+1 是一个整数,表示第i头牛的高度. Output * Line 1: 一个整数表示c[ ...
- Bzoj 1726: [Usaco2006 Nov]Roadblocks第二短路 dijkstra,堆,A*,次短路
1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 969 Solved: 468[S ...
- Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 554 Solved: 346[ ...
- Bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声 单调栈
1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 631 Solved: 445[Submi ...
- BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )
有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...
随机推荐
- js调试若干
主要是将 chrome调试工具 firebug的控制台对以下都有支持 consoleAPI https://developers.google.com/chrome-developer-tools ...
- 小猪猪C++笔记基础篇(五)表达式、语句
小猪猪C++笔记基础篇(五) 关键词:表达式.语句 本章的内容比较简单,基本上没有什么理解上的困难,都是知识上的问题.先开始想要不要写呢,本来是不准备写的,但是既然读了书就要做笔记,还是写一写,毕竟还 ...
- javascript 绝对路径工具类
// #region 取虚拟目录示例代码 //获取网站虚拟目录名称 function GetVirtualDirectoryName() { var pathname = removeFirstSla ...
- JS中的内存泄漏
明天下午面试微店的前端开发职位,有点紧张~~ 刚刚正好看到js中的内存泄露,所以来整理一番. 给DOM对象添加的属性是对一个js对象的引用. var MyObject = {}; document.g ...
- 对程序员的不尊重是中国it产业的悲哀。
电脑刚进入中国时,“程序员”三个字是一份令人尊敬的岗位,那个时候中国互联网人才奇缺.程序员的价格也就水涨船高.小的时候电视里到处播放着电脑培训学院的招生广告.一说到程序员,给我们的印象都是白领,高薪的 ...
- spring boot 下 500 404 错误页面处理
spring boot 作为微服务的便捷框架,在错误页面处理上也有一些新的处理,不同于之前的spring mvc 500的页面处理是比较简单的,用java config或者xml的形式,定义如下的be ...
- A Brief Introduction to Multiset[STL]
基础 multiset是<set>库中一个非常有用的类型,它可以看成一个序列,插入一个数,删除一个数都能够在O(logn)的时间内完成,而且他能时刻保证序列中的数是有序的,而且序列中可以存 ...
- PE框架学习之道:PE框架——发送报文流程
PE框架发送报文,适用于PE及VX技术 步骤: 1.在action中使用发送报文,要指定报文在router端的交易名称 2.如果使用supe.execute(context)来发送,不需要第一步 3. ...
- Android SDK三种更新失败及其解决方法
更新Android SDK,居然失败了三次. 1.第一次失败 出现Failed to fetch URL错误提示 Failed to fetch URL https://dl-ssl.google.c ...
- centos 安装 erlang
1.首先下载erlang 安装源文件 可以在官网上下载 : http://www.erlang.org/ 官网上提供多个版本: 2.下载完成后将R16B01 Source File对应的 ot ...