题目


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

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)

题解


处理点的关系,最短路跑一遍!


代码


 /*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 攀岩的更多相关文章

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

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

  2. [Usaco2006 Open]The Climbing Wall 攀岩

    Description One of the most popular attractions at the county fair is the climbing wall. Bessie want ...

  3. BZOJ1665 : [Usaco2006 Open]The Climbing Wall 攀岩

    直接BFS貌似复杂度飞起来了,于是我们用k-d tree优化找点的过程即可.时间复杂度$O(n\sqrt{n})$. #include<cstdio> #include<algori ...

  4. BZOJ 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 [后缀数组]

    1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1017  Solved: ...

  5. BZOJ 1660: [Usaco2006 Nov]Bad Hair Day 乱发节

    Description Input * Line 1: 牛的数量 N. * Lines 2..N+1: 第 i+1 是一个整数,表示第i头牛的高度. Output * Line 1: 一个整数表示c[ ...

  6. Bzoj 1726: [Usaco2006 Nov]Roadblocks第二短路 dijkstra,堆,A*,次短路

    1726: [Usaco2006 Nov]Roadblocks第二短路 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 969  Solved: 468[S ...

  7. Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 346[ ...

  8. Bzoj 1657: [Usaco2006 Mar]Mooo 奶牛的歌声 单调栈

    1657: [Usaco2006 Mar]Mooo 奶牛的歌声 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 631  Solved: 445[Submi ...

  9. BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )

    有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...

随机推荐

  1. 2014-07-23 利用ASP.NET自带控件实现单文件上传与下载

    效果图 上传文件页面: 下载文件页面:  1.母版页site.Master <%@ Master Language="C#" AutoEventWireup="tr ...

  2. Node.js 小工具--supervisor

    Node.js 在写文件的时候 一旦更改.每次都得重新运行 app.js. 很麻烦. supervisor 工具可以帮助你 监听文件改动,自动重启. sudo npm install -g super ...

  3. 我的IOS学习之路(三):手势识别器

    在iOS的学习中,对于手势的处理是极为重要的,如对于图片,我们经常需要进行旋转,缩放以及移动等.这里做一下总结,详见代码. - (void)viewDidLoad { [super viewDidLo ...

  4. 一道试题引发的血案 int *ptr2=(int *)((int)a+1);

    某日,看到一道比较恶心的C语言的试题,考了很多比较绕的知识点,嘴脸如下: int main(void) { int a[4] = {1, 2, 3, 4}; int *ptr1=(int *)(&am ...

  5. Problem A: A + B

    Problem A: A + BTime Limit: 1 Sec Memory Limit: 128 MBSubmit: 17 Solved: 10[Submit][Status][Web Boar ...

  6. Lucence.net索引技术 二

    一. Lucene索引创建和优化 [版本2.9.0以上] Lucene索引的创建首先需要取得几个必须的对象: 1.分词器//可以采用其他的中文分词器 StandardAnalyzer analyzer ...

  7. Java "JSON中无分隔符日期字符串处理"

    Json 中日期类型数据处理,服务端传输的日期没有分隔符,一般格式就两种,[20151212121212]即yyyyMMddhhmmss和[121212]hhmmss import java.text ...

  8. jQuery File Upload 插件 php代码分析

    jquery file upload php代码分析首先进入构造方法 __construct() 再进入 initialize()因为我是post方式传的数据  在进入initialize()中的po ...

  9. 别忘记给你博客的windows live writer配置 ping服务

    写好一篇博客,想要实现秒收.就必须要为文章添加ping服务. 这里介绍一下给wlw添加ping服务的办法. 点击工具---选项--ping服务器. 在右侧栏中加入以下地址 http://rpc.pin ...

  10. Correlation rule tuning

    Lots of organizations are deploying SIEM systems either to do their due diligence or because it’s pa ...