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 )
有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...
随机推荐
- hdu 4612 Warm up 双连通缩点+树的直径
首先双连通缩点建立新图(顺带求原图的总的桥数,事实上因为原图是一个强连通图,所以桥就等于缩点后的边) 此时得到的图类似树结构,对于新图求一次直径,也就是最长链. 我们新建的边就一定是连接这条最长链的首 ...
- xcode 工具栏中放大镜的替换的简单说明
1.如果是在打开的文档范围内: 查找: Command+ F 替换: Option+Command+F Replace All 是全部替 ...
- SqlDataAdapter的方法之一Fill (DataSet dataset, String datatable)解释
一.SqlDataAdapter的方法之一Fill (DataSet dataset, String datatable)解释:根据datatable名填充Dataset.myda.Fill(ds, ...
- compass安装教程
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- 关于ASP控件对象的一些简单操作
在线人数 Application.Lock(); Application[).ToString(); Application.UnLock(); Label1.Text = Application[& ...
- C# - 通过自定义注解反射生成SQL语句[转]
转自http://blog.163.com/jong_cai/blog/static/87028045200902033553581/ -------------------------------- ...
- HDU2023-求平均成绩
描述: 假设一个班有n(n<=50)个学生,每人考m(m<=5)门课,求每个学生的平均成绩和每门课的平均成绩,并输出各科成绩均大于等于平均成绩的学生数量. 输入数据有多个测试实例,每个测试 ...
- c 结构体 简单的了解
1.声明一个学生类的 结构体 struct Student{ int age; char name[20];//长度为20的字符串 int weiht;//像正常一样的申请变量,这个变量属于结构体的一 ...
- 高质量程序设计指南C/C++语言——C++/C常量(2)
- 关于js的一些关键知识点(call,apply,callee, caller,clourse,prototypeChain)
可能不少学习javascript在使用call,apply,callee时会感到困惑,以下希望对于你有所帮助: 1.~~~call ,apply是函数(函数对象)的方法:callee是函数argume ...