메뉴 건너뛰기

Programing

BAEKJOON

2585

관리자 2019.12.21 15:31 조회 수 : 127

C++

#include <cstdio>

#include <cmath>

#include <cstring>

#include <queue>

#include <algorithm>

using namespace std;

struct Pos{

    int x;

    int y;

};

struct Q_info{

    int x;

    int y;

    int i;

    int t;

};

int dist[1010][1010];

int N,K;

Pos pos[1010];

int check[1010];

queue<Q_info> q;

int serch(int L){

    while(!q.empty()){

        Q_info info=q.front();

        q.pop();

        if(info.x==10000&&info.y==10000){

            return 1;

        }

        if(info.t<=K){

            for(int i=1;i<=N+2;i++){

                if(check[i]==1||i==info.i)

                    continue;

                if(dist[info.i][i]<=L){

                    check[i]=1;

                    q.push({pos[i].x,pos[i].y,i,info.t+1});

                }

 

            }

        }

    }

    return 0;

}

int main()

{

    scanf("%d %d",&N,&K);

    pos[1].x=0;

    pos[1].y=0;

    for(int i=2;i<=N+1;i++){

        scanf("%d %d",&pos[i].x,&pos[i].y);

    }

    pos[N+2].x=10000;

    pos[N+2].y=10000;

    for(int i=1;i<=N+2;i++){

        for(int j=1;j<=N+2;j++){

            if(i==j)

                continue;

            //int a=sqrt((double)(pow(pos[i].x-pos[j].x,2)+pow(pos[i].y-pos[j].y,2)));

            //dist[i][j]=a/10+1;

            dist[i][j]=ceil(sqrt((double)(pow(pos[i].x-pos[j].x,2)+pow(pos[i].y-pos[j].y,2))) / 10.0);

        }

    }

    int lb=1,ub=1415;

    while(lb<ub){

        int c = (ub+lb)/2;

        while( !q.empty() ) q.pop();

        q.push({0,0,1,0});

        memset(check,0,sizeof(check));

        check[1]=1;

        int a=serch(c);

        if(a==1){

            ub=c;

        }else{

            lb=c+1;

        }

    }

    printf("%d",ub);

    return 0;

}

번호 제목 글쓴이 날짜 조회 수
공지 안내사항 관리자 2019.12.21 173
74 9663 관리자 2019.12.21 124
73 9345 관리자 2020.04.11 160
72 9019 관리자 2019.12.21 125
71 7569 관리자 2019.12.21 123
70 6987 관리자 2019.12.21 125
69 5842 관리자 2020.04.11 161
68 5625 관리자 2019.12.21 119
67 5419 관리자 2020.04.11 166
66 3392 관리자 2020.04.11 166
65 3019 관리자 2019.12.21 121
64 2933 관리자 2019.12.21 123
63 2931 관리자 2019.12.21 121
62 2836 관리자 2019.12.21 120
61 2667 관리자 2019.12.21 123
60 2636 관리자 2019.12.21 123
59 2629 관리자 2020.04.11 156
58 2615 관리자 2019.12.21 121
57 2610 관리자 2020.04.11 158
56 2606 관리자 2019.12.21 121
» 2585 관리자 2019.12.21 127
54 2578 관리자 2019.12.21 121
53 2573 관리자 2020.04.11 161
52 2557 관리자 2019.12.21 121
51 2512 관리자 2019.12.21 121
50 2504 관리자 2020.04.11 157
49 2481 관리자 2019.12.21 122
48 2478 관리자 2020.04.11 158
47 2473 관리자 2020.04.11 163
46 2470 관리자 2020.04.11 161
위로