poj 1806 Manhattan 2025

Manhattan 2025

Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 2368 Accepted: 1100

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..
.....
.....

题目大意:给定一个正整数n(0≤n≤9),按样例的输出格式将其输出。

Solution: 就是一个直接输出的问题。下面采取的是二维数组的方法。只需要两个参数就可以确定某一个slice的输出结果。getSlice(int n, int m)方法中n表示的是从键盘输入的值,m表示二维数组中心的值。然后根据m按曼哈顿距离(02143025_mNdy.png)计算它周边的点的值,然后直接输出即可。

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void getSlice(int n, int m) {
        if (n == 0) {
            System.out.println("0");
            return;
        }

        char[][] matrix = new char[2 * n + 1][2 * n + 1];
        for (int i = 0; i < 2 * n + 1; i++) {
            for (int j = 0; j < 2 * n + 1; j++) {
                int t = Math.abs(i - n) + Math.abs(j - n);
                if (t + m <= n) {
                    matrix[i][j] = (char)(m + t + '0');
                } else {
                    matrix[i][j] = '.';
                }
            }
        }

        for (int i = 0; i < 2 * n + 1; i++) {
            for (int j = 0; j < 2 * n + 1; j++) {
                System.out.print(matrix[i][j]);
            }
            System.out.println();
        }
    }

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int j = 0; j < n; j++) {
            int t = Integer.parseInt(br.readLine());
            System.out.println("Scenario #" + (j + 1) + ":");
            for (int i = 0; i < 2 * t + 1; i++) {
                System.out.println("slice #" + (i + 1) + ":");
                getSlice(t, Math.abs(i - t));
            }
            if (j != n - 1) {
                System.out.println();
            }
        }
        br.close();
    }
}

 

转载于:https://my.oschina.net/yitiaoxianyu/blog/1559809

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值