Sicily 1709:PropBot(BFS)

Posted Vincent_Bryan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Sicily 1709:PropBot(BFS)相关的知识,希望对你有一定的参考价值。

 

#include<bits/stdc++.h>
using namespace std;
int TIME;
double X, Y;
double MIN;
double MIN_X, MIN_Y;
double SQRT = sqrt(0.5);
double DIR[8][2] = {{1,0}, {SQRT, -1*SQRT}, {0, -1}, {-1*SQRT, -1*SQRT}, 
                    {-1, 0}, {-1*SQRT, SQRT}, {0, 1}, {SQRT, SQRT}};
map<double, int> m[8];
struct Node{
    double x, y;
    int dir;
    int time;
}; 
double dist(Node n){
    return ((n.x - X)*(n.x - X) + (n.y - Y)*(n.y - Y));
}

void BFS(){
    Node n;
    n.x = n.y = 0;
    n.time = 0;
    n.dir = 0;
    queue<Node>q;
    if(n.time <= TIME){
        if(dist(n) < MIN){
            MIN = dist(n);
            MIN_X = n.x;
            MIN_Y = n.y;
        }
        q.push(n);
    } 
    
    while(!q.empty()){
        Node front = q.front();
        q.pop();
        double d = dist(front);
        Node t1 = front;
        t1.x += 10*DIR[t1.dir][0];
        t1.y += 10*DIR[t1.dir][1];
        t1.time++;
        if(t1.time <= TIME){
            if(dist(t1) < MIN){
                MIN = dist(t1);
                MIN_X = t1.x;
                MIN_Y = t1.y;
            }
            q.push(t1);
        }
        Node t2 = front;
        t2.dir = (++t2.dir) ;
        t2.time++;
        if(t2.time <= TIME && t2.dir < 8){
            q.push(t2);
        }
    }
}
int main(){
    int t;
    cin >> t;
    while(t--){
        cin >> TIME >> X >> Y;
        MIN = 10000000;
        for(int i = 0; i < 8; i++){
            m[i].clear();
        }
        BFS();
        printf("%.6f\\n", sqrt(MIN));
    }
}                        

 

以上是关于Sicily 1709:PropBot(BFS)的主要内容,如果未能解决你的问题,请参考以下文章

Sicily 1150. 简单魔板

ZOJ 1709(BFS_A题)解题报告

Sicily 1021 Couple

Sicily 1176 Two Ends

Sicily 1046 Plane Spotting

Sicily 1020 Big Integer