POJ1806 Manhattan 2025

POJ1806
Description
Background
Manhattan in the year 2025 - it is so densely populated that its old two-dimensional grid of streets
and avenues fails to provide enough space for all the traditional vehicles such as cars, bicycles, or
busses.Accordingly, the newly developed 3D-Skyjetters become very popular, because they allow to pass
the traffic jams on the ground by flying in the air. After a series of horrible accidents caused by
3D-Skyjetters cutting a corner, New York authorities have put into place new regulations of air traffic
and are determined to enforce them rigorously. The key point of these regulations is that 3D-Skyjetters
must follow virtual airways on a three-dimensional rectangular grid, easy enough for the New Yorkers
who had to use the two-dimensional rectangular grid of roads on the ground all their life.
Problem
You own a company that rents out 3D-Skyjetters. As 3D-Skyjetters are in such an early state of development,
they are far from being economical. So your customers keep running out of petrol at all the wrong places,
and you need a system to inform them about their current range at all times.
You may assume that travelling from one intersection to the next in the grid takes one unit of petrol,
no matter if the customer is moving horizontally or vertically, up or down. You may also assume that your
customer is located at some intersection where his or her movements are not restricted by the ground or
other obstacles, but just by the amount of remaining petrol.
Given the amount of petrol, provide a graphical representation of all the intersections in the range of
your customer, along with the amount of petrol that is needed to go there.

Input
The first line of the input contains the number of scenarios. For each scenario, there is a line containing
the units of remaining petrol, i.e an integer u satisfying 0 <= u <= 9. If more than 9 units of petrol remain,
the customer will ignore the display anyway.
Output

Start the output for each scenario with a line containing "Scenario #i:", where i is the number of the scenario
starting at 1. Then print a graphical (or rather textual) representation of all intersections that can be
reached with the given amount of petrol, along with the units of petrol necessary to go there. In this
graphical representation, print the slices of the smallest axis-aligned three-dimensional cube containing
all the intersections in the range, and label the slices from the bottom to the top starting at 1. For each
slice,start the output with a line containing "slice #s:", where s is the number of the slice. In the lines
that follow, print a graphical representation of all the intersections in that slice, using

the digits 0 to 9 for intersections in the range, representing the amount of petrol necessary to go there,

and the dot "." for intersections not in the range.

Print an additional blank line after each scenario.
Sample Input
2
0
2
Sample Output

Scenario #1:
slice #1:
0

Scenario #2:
slice #1:
.....
.....
..2..
.....
.....
slice #2:
.....
..2..
.212.
..2..
.....
slice #3:
..2..
.212.
21012
.212.
..2..
slice #4:
.....
..2..
.212.
..2..
.....
slice #5:
.....
.....
..2..
.....
.....

曼哈顿 2025
描述
背景
曼哈顿2025年的时候,由于人口众多导致它二维的街道不能为所有的传统交通工具提供足够的空间,比如汽车,摩托车,
巴士等等。因此,新发明的三维空路变得流行,因为他们可以通过在空中飞行穿过地上的堵塞的交通。一系列恐怖的交通
事故之后,纽约当局发布了新的空中交通条款并强制执行。规则的关键点在于3d空中摩托必须沿着3维空间矩形网格的虚
拟路线行进,这对于习惯了周围生活中二维矩形网格路的纽约人就容易多了。
问题
你有一家公司出租3D飞行器。因为3D飞行器在开发的初期,他们并不经济。所以你的客户经常在很多错误的地点消耗完
汽油,你需要一个系统来一直提醒他们他们当前的范围。
你可以假设从一个交叉点到网格中的下一个点需要1个单位的汽油,无论客户是水平走、垂直走、向上走、向下走。你
还可以假设你的客户在某个交叉点,在那个交叉点,它的行动不被地面或者其他障碍所限制,但是受限于剩余的汽油。
给一定数量的汽油,提供给你的客户所能到达范围的全部交点的简图以及到达该点需要的汽油数量。
输入
输入的第一行包括场景的数量。
每一个场景,有一行数据表示剩余的汽油数量,比如整型u满足0-9.如果汽油数量多余9,客户可以忽视显示屏的提示信息。
输出
每个场景的输出第一行是"Scenario #i:",其中i是场景号,从1开始计算。
然后打印一个图形化显示的可以用剩余数量的汽油到达的全部交叉点以及到达那里需要的汽油数,在这个图形显示中,打印
最小层对称的三维立方体包括范围内的所有焦点,还有为层贴标签从底到顶,从1开始。
每一层,以输出"slice #s:"开始,s是层的序号。
在接下来的几行,将该层中全部交点以以图的形式表示出来,用数字0-9表示焦点的范围,表示到达该点需要的汽油数。
点‘.’表示不在范围内的交点。
每一个场景之后输出一个额外的空行。
输入例子:
2//场景个数
0//还剩0个汽油
2//还剩2个汽油
输出例子:
Scenario #1:
slice #1:
0

Scenario #2:
slice #1:
.....
.....
..2..
.....
.....
slice #2:
.....
..2..
.212.
..2..
.....
slice #3:
..2..
.212.
21012
.212.
..2..
slice #4:
.....
..2..
.212.
..2..
.....
slice #5:
.....
.....
..2..
.....
.....

Problem: 1806   User: qq1203456195
Memory: 168K   Time: 32MS
Language: C   Result: Accepted
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int Scenario,Oil,Slice,M[30][30];
void Display()
{
    int i,j;
    for (i=0;i<Slice;i++)
    {
        for (j=0;j<Slice;j++)
        {
            if (M[i][j]<=Oil)
                printf("%d",M[i][j]);
            else
                printf(".");
        }
        printf("\n");
    }
}
void left_up(int x,int y,int m,int t)
{
    if (m==Oil+1)
        return;
    M[x][y]=m;
    left_up(x-1,y,m+t,t);
    left_up(x,y-1,m+t,t);

}
void up_right(int x,int y,int m,int t)
{
    if (m==Oil+1)
        return;
    M[x][y]=m;
    up_right(x,y-1,m+t,t);
    up_right(x+1,y,m+t,t);
}
void right_down(int x,int y,int m,int t)
{
    if (m==Oil+1)
        return;
    M[x][y]=m;
    right_down(x+1,y,m+t,t);
    right_down(x,y+1,m+t,t);

}
void down_left(int x,int y,int m,int t)
{
    if (m==Oil+1)
        return;
    M[x][y]=m;
    down_left(x,y+1,m+t,t);
    down_left(x-1,y,m+t,t);
}
void func(int m,int t,int x,int y)
{
    left_up(x,y,m,t);
    up_right(x,y,m,t);
    right_down(x,y,m,t);
    down_left(x,y,m,t);
}
int main()
{
    int i,j,x,y;
    scanf("%d",&Scenario);
    for(i=1;i<=Scenario;i++)
    {
        scanf("%d",&Oil);
        printf("Scenario #%d:\n",i);
        if (Oil==0)
        {
            printf("slice #1:\n0\n");
        }
        else
        {
            Slice=2*Oil+1;
            for (j=1;j<=Slice;j++)
            {
                memset(M,10,sizeof(M));
                x=Oil;
                y=Oil;
                printf("slice #%d:\n",j);
                if (j<=Oil+1)
                    func(Oil-j+1,1,x,y);
                else
                    func(j-Oil-1,1,x,y);
                Display();
            }
        }
        printf("\n");
    }
    return 0;
}
字节跳动内推

找我内推: 字节跳动各种岗位
作者: ZH奶酪(张贺)
邮箱: cheesezh@qq.com
出处: http://www.cnblogs.com/CheeseZH/
* 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/CheeseZH/p/2457879.html