zoukankan      html  css  js  c++  java
  • BZOJ1665 Usaco2006 Open The Climbing Wall

    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;
    }
    

      

  • 相关阅读:
    (原创)Protel与Altium Designer的前生今世(PCB)
    什么是C语言
    [转帖]s3c4410中断解析(ARM)
    (原创)Protel对话窗字体显示不完全问题解决办法(PCB)
    (原创)VC运行缺少NMSQL.DLL
    C语言中#include命令中,文件名用双撇号和尖括号括起来用法的区别
    UI小综合+跳转
    UITextFieldIOS开发
    UIControlIOS开发
    在SharePoint开发中引入Composite Web Application Block
  • 原文地址:https://www.cnblogs.com/something-for-nothing/p/8031090.html
Copyright © 2011-2022 走看看