메뉴 건너뛰기

Programing

BAEKJOON

2585

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

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 165
74 9663 관리자 2019.12.21 116
73 9345 관리자 2020.04.11 152
72 9019 관리자 2019.12.21 115
71 7569 관리자 2019.12.21 115
70 6987 관리자 2019.12.21 115
69 5842 관리자 2020.04.11 153
68 5625 관리자 2019.12.21 111
67 5419 관리자 2020.04.11 158
66 3392 관리자 2020.04.11 158
65 3019 관리자 2019.12.21 113
64 2933 관리자 2019.12.21 114
63 2931 관리자 2019.12.21 113
62 2836 관리자 2019.12.21 112
61 2667 관리자 2019.12.21 115
60 2636 관리자 2019.12.21 115
59 2629 관리자 2020.04.11 148
58 2615 관리자 2019.12.21 113
57 2610 관리자 2020.04.11 148
56 2606 관리자 2019.12.21 113
» 2585 관리자 2019.12.21 115
54 2578 관리자 2019.12.21 113
53 2573 관리자 2020.04.11 153
52 2557 관리자 2019.12.21 113
51 2512 관리자 2019.12.21 113
50 2504 관리자 2020.04.11 149
49 2481 관리자 2019.12.21 114
48 2478 관리자 2020.04.11 150
47 2473 관리자 2020.04.11 155
46 2470 관리자 2020.04.11 153
위로