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 )
有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...
随机推荐
- Cocos2d-x3.0 捕Android菜单键和返回键
原文地址:http://blog.csdn.net/qqmcy/article/details/26172665 .h void onKeyReleased(EventKeyboard::KeyCod ...
- Head First SQL笔记
看的时候总结了一下,如下: Chapter 1: 创建数据库 CREATE DATABASE database_name; 使用数据库 USE database_name; 创建表 CRATE TAB ...
- ASP.NET快速开发框架、这才是高大上档次后台管理UI界面
另外献上在<线体验Demo地址>希望大家也能从中得到一些启发.地址:http://121.40.148.178:8080/ . 用户名:guest,密码:123456QQ技术交流群:239 ...
- 我的一个关于RFID的项目总结
去年做的一个项目,今天在这里想总结一下,这是主要流程: [0]RFID(Reader)---->[1]网络---->[2]接收处理程序---->[3]队列---->[4]读/存 ...
- Auto-Layout 的各种坑Unable to create description in descriptionForLayoutAttribute_layoutItem_coefficient. Something is nil'
我们的很多人现在都在使用autolayout,用着也是非常爽但是有了这个东西以后更爽 很省事,什么都不用自己搞.Xcode完全搞定了,但是我终于为自己的懒惰付出了代价,再iphone4怎么运行怎么cr ...
- C++ 字符串指针与字符串数组
在做面试100题中第21题时,发现char *astr="abcdefghijk\0";和char astr[]={"abcdefghijk"};有点区别,以前 ...
- R语言学习之主成分分析法的R实践
主成分分析R软件实现程序(一): >d=read.table("clipboard",header=T) #从剪贴板读取数据 >sd=scale(d) #对数据进行标 ...
- python的内置函数bin()
bin(x) 中文说明:将整数x转换为二进制字符串,如果x不为Python中int类型,x必须包含方法__index__()并且返回值为integer: 参数x:整数或者包含__index__()方法 ...
- selenium 学习笔记 ---新手学习记录(7) 问题总结(java)
1.想要获取固定ul下所有li的个数 如下图: //获取ul下li的个数 List<WebElement> elements = driver.findElement(By.id(&qu ...
- C单链表实现
/* * LinkNode.c * * Created on: Jan 14, 2014 * Author: root */ #include <stdlib.h> #include &l ...