메뉴 건너뛰기

Programing

BAEKJOON

2585

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

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 175
74 9663 관리자 2019.12.21 126
73 9345 관리자 2020.04.11 167
72 9019 관리자 2019.12.21 128
71 7569 관리자 2019.12.21 128
70 6987 관리자 2019.12.21 131
69 5842 관리자 2020.04.11 163
68 5625 관리자 2019.12.21 125
67 5419 관리자 2020.04.11 173
66 3392 관리자 2020.04.11 168
65 3019 관리자 2019.12.21 125
64 2933 관리자 2019.12.21 125
63 2931 관리자 2019.12.21 126
62 2836 관리자 2019.12.21 122
61 2667 관리자 2019.12.21 128
60 2636 관리자 2019.12.21 125
59 2629 관리자 2020.04.11 158
58 2615 관리자 2019.12.21 123
57 2610 관리자 2020.04.11 160
56 2606 관리자 2019.12.21 123
» 2585 관리자 2019.12.21 129
54 2578 관리자 2019.12.21 123
53 2573 관리자 2020.04.11 163
52 2557 관리자 2019.12.21 123
51 2512 관리자 2019.12.21 126
50 2504 관리자 2020.04.11 159
49 2481 관리자 2019.12.21 124
48 2478 관리자 2020.04.11 160
47 2473 관리자 2020.04.11 165
46 2470 관리자 2020.04.11 163
위로