용감한 오리 (BRAVEDUCK) 왜 오답인지 모르겠습니다..

  • User Avatar
    draner

    [[problem:BRAVEDUCK]]

    노드를 만들어주고 jump보다 낮으면 간선을 연결하였습니다.

    그리고 플로이드를 통해서 최단거리를 구하고.

    연결안된지즘은 INF이므로 출력할떄 다음과같이 했습니다..

    무엇이 문제일까요...

    코드
    ~~~ c++
    #include
    #include
    using namespace std;
    #define INF 1000000

    int map[2002][2002];
    int A[2002][2002];
    int arr[2002][3];
    int jump,stoneCnt;

    double dist(int x,int y, int x2,int y2){

    if(x==x2 || y==y2){
        double t = (x2-x)*(x2-x)  + (y2-y)*(y2-y) ;
        double temp = sqrt(t);
        return temp;
    }
    else
    {
        return INF;
    }
    

    }

    void solve(){

    int i, j, k; 
    for(i=0; i<stoneCnt+2; i++) 
        for(j=0; j<stoneCnt+2; j++) 
            A[i][j]=map[i][j];
    for(k=0; k<stoneCnt+2; k++){ 
        for(i=0; i<stoneCnt+2; i++) 
            for(j=0; j<stoneCnt+2; j++) 
                if (A[i][k]+A[k][j] < A[i][j]) {
                    A[i][j] = A[i][k]+A[k][j]; 
                }
    
    } 
    

    }
    int main(){

    int testcase ;
    int startx,starty,endx,endy;
    int x,y;
    
    cin>>testcase;
    for(int t= 0;t<testcase ;t++){
    
        cin>>jump;
        //시작은 0번 정점
        cin>>startx>>starty;
        arr[0][0]= startx;
        arr[0][1] =starty;
        //끝은  1번 정점
        cin>>endx>>endy;
        arr[1][0]= endx;
        arr[1][1] =endy;
    
    
        cin>>stoneCnt;
    
        //나머지 노드들 을 넣어줌
        for(int i=0; i<stoneCnt; i++){
            cin>>x>>y;
            arr[i+2][0] =x;
            arr[i+2][1] =y;
    
        }
    
        //map초기화.
        for(int i=0;i<stoneCnt+2;i++){
            for(int j=0; j< stoneCnt+2; j++){
                map[i][j] =INF;
                A[i][j]=0;
            }
        }
    
        //유클리디언으로 jump가능하면 노드들을 간선을 1로 연결하기.
        for(int i=0; i<stoneCnt+2;i++){
            for(int j=0; j<stoneCnt+2; j++){
                if( dist(arr[i][0],arr[i][1],arr[j][0],arr[j][1]) <=jump){
                    map[i][j]=1;
                }
            }
        }
    
    
        //자기자신은 갈수없으므로 0;
        for(int i=0;i<stoneCnt+2;i++)
            map[i][i] =0;
    
        //플로이드.
        solve();
    
        //시작에서 끝까지 못가면 INF므로 NO
        if(A[0][1]==INF){
            cout<<"NO"<<endl;
        }
        else{
            cout<<"YES"<<endl;
        }
    
    }
    

    }


    10년 전
1개의 댓글이 있습니다.
  • User Avatar
    draner

    스스로 해결했습니다. 혹시 저같은 실수를 하시는분이있지않을까하여 답변을 답니다.. map에 INF를 채우지 않고 0으로 초기화해논상태에서 하면 정답이.. 뜹니다..

    왜그런지는.. 코드를 더 보겠습니다.


    10년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.