Find a way HDU - 2612

原oj网址点击打开链接

vj网址点击打开链接

这道题 水题 但是在一开始比赛的时候不知道为啥 总是 样例错 当时是 各种怀疑人生啊 ~~~ 最后才发现 是一个字母写错了  队友已经磨刀差点砍我了  这道题的意思就是  有两个人 在图上显示 y m 然后 @是 kfc 他们两个是 想到距离最短的kfc去聊聊天 什么的 然后问你 需要的最短时间 (每走一步是11min) 然后 这道题 直接 两遍bfs 就过的轻轻松松 直接 把 到的时间 存在数组里 就行  然后这道题 就过去了 

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
char p[300][300];
struct ppx
{
    int x, y, z;
} as, ad, af, ag;
int k[5] = { -1, 0, 0, 1};
int kk[5] = {0, 1, -1, 0};
int ass[300][300];
int add[300][300];
bool bj[300][300];
int n, m, maxx;
void bfs()
{
    memset(bj, 0, sizeof(bj));
    queue<ppx>q;
    bj[as.x][as.y]=1;
    q.push(as);
    while(!q.empty())
    {
        af = q.front();
        q.pop();
        //printf("%d %d\n",af.x,af.y);
        if(p[af.x][af.y] == '@')
        {
          //  printf("%c\n",p[af.x][af.y]);
    //  printf("%d %d    0 \n",af.x,af.y);
            ass[af.x][af.y] = af.z;
        }
        for(int i = 0; i < 4; i++)
        {
            ag = af;
            ag.x = af.x + k[i];
            ag.y = af.y + kk[i];
            if(ag.x >= 0 && ag.x < n && ag.y >= 0 && ag.y < m && p[ag.x][ag.y] != '#' && !bj[ag.x][ag.y])
            {
                bj[ag.x][ag.y] = 1;
                ag.z = af.z + 1;
                q.push(ag);
            }
        }
    }
    memset(bj, 0, sizeof(bj));
    bj[ad.x][ad.y]=1;
    queue<ppx>qq;
    qq.push(ad);
    while(!qq.empty())
    {
        af = qq.front();
        qq.pop();
        if(p[af.x][af.y] == '@')
        {
            add[af.x][af.y] = af.z;
        }
        for(int i = 0; i < 4; i++)
        {
            ag = af;
            ag.x = af.x + k[i];
            ag.y = af.y + kk[i];
            if(ag.x >= 0 && ag.x < n && ag.y >= 0 && ag.y < m && p[ag.x][ag.y] != '#' && ! bj[ag.x][ag.y])
            {
                bj[ag.x][ag.y] = 1;
                ag.z = af.z + 1;
                qq.push(ag);
            }
        }
    }
}
int main()
{
    while(~scanf("%d%d", &n, &m))
    {
         maxx =1000000+1 ;
        memset(bj, 0, sizeof(bj));
        for(int i = 0; i < n; i++)
        {
            scanf("%s", p+i);
            for(int j = 0; j < m; j++)
            {
                 ass[i][j]=1000000;
                 add[i][j]=1000000;
                if(p[i][j] == 'Y')
                {
                    as.x = i, as.y = j, as.z = 0;
                }
                if(p[i][j] == 'M')
                {
                    ad.x = i, ad.y = j, ad.z = 0;
                }
            }
        }
        bfs();
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(ass[i][j] == 1000000|| add[i][j] == 1000000)
                    continue;
                maxx = min(maxx, ass[i][j] + add[i][j]);
            }
        }
        printf("%d\n", maxx*11);
    }
    return 0;
}

Find A Way

11-25

Problem DescriptionnWe'll consider an interesting geometric problem here. Given a number of circles with varying radius on the plane, and define the P-value of a point (x, y) on the plane as the number of circles covering this point. Here, by "covering", we mean that the point is either strictly within the circle, or on the boundary of the circle.nGiven the starting position (Sx, Sy), and the destination position (Tx, Ty), please find a path between the two points, such that every point of the path is on the boundary of one or more circles, and the absolute difference between the maximum P-value and the minimum P-value among all points on the path is minimized. nCan you find the minimum absolute value with the help of your computer?n nnInputnThere are multiple test cases in the input file. Each test case starts with one integer N (1 <= N <= 150), the number of circles, followed by four real numbers, Sx, Sy, Tx, Ty, representing the x-coordinate and y-coordinate of the starting position and the destination. Each of the following N lines consists of three real numbers X, Y and R (R >= 1), indicating that there is a circle at position (X, Y) with radius R.nThere is a blank line after each test case. Input ends with End-of-File.nNote: It is guaranteed that the input data is always legal, i.e. both the starting position and the destination are on the boundary of one or more circles, no two circles will be at the same position, every real number in the input file has at most three digits after the decimal point, and the absolute value of any real number does not exceed 10000.n nnOutputnFor each test case, output one integer on one separate line as requested. If there is no way to reach the destination, output -1 instead.n nnSample Inputn2n-1.000 0.000 1.000 0.000n0.000 0.000 1.000n1.000 0.000 1.000nn2 n-1.000 0.000 5.000 0.000n-1.000 -1.000 1.000n4.000 0.000 1.000n nnSample OutputnCase 1: 1nCase 2: -1n

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭