poj 1806 分块模拟

时间:2022-06-15 13:03:19
Manhattan 2025
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 1318   Accepted: 703

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

Source

TUD Programming Contest 2003, Darmstadt, Germany
#include <stdio.h>
#include <string.h>
#include <stdlib.h> int Scenario,Oil,Slice,M[][];
void Display()
{
int i,j;
for (i=;i<Slice;i++)
{
for (j=;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+)
return;
M[x][y]=m;
left_up(x-,y,m+t,t);
left_up(x,y-,m+t,t); }
void up_right(int x,int y,int m,int t)
{
if (m==Oil+)
return;
M[x][y]=m;
up_right(x+,y,m+t,t);
up_right(x,y-,m+t,t);
}
void right_down(int x,int y,int m,int t)
{
if (m==Oil+)
return;
M[x][y]=m;
right_down(x+,y,m+t,t);
right_down(x,y+,m+t,t); }
void down_left(int x,int y,int m,int t)
{
if (m==Oil+)
return;
M[x][y]=m;
down_left(x,y+,m+t,t);
down_left(x-,y,m+t,t);
}
void func(int x,int y,int m,int t)
{
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=;i<=Scenario;i++)
{
scanf("%d",&Oil);
printf("Scenario #%d:\n",i);
if (Oil==)
{
printf("slice #1:\n0\n");
}
else
{
Slice=*Oil+;
for (j=;j<Slice;j++)
{
memset(M,,sizeof(M));
x=Oil;
y=Oil;
printf("slice #%d:\n",j+);
if (j<=Oil)
func(x,y,Oil-j,);
else
func(x,y,j-Oil,);
Display();
}
}
printf("\n");
}
return ;
}

注意方位的把握~~~

poj 1806 分块模拟的更多相关文章

  1. P1972 &lbrack;SDOI2009&rsqb;HH的项链&lbrack;离线&plus;树状数组&sol;主席树&sol;分块&sol;模拟&rsqb;

    题目背景 无 题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不断地收集新的贝壳,因此,他的项链 ...

  2. poj 3077Rounders(模拟)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://po ...

  3. POJ 1068 Parencodings 模拟 难度&colon;0

    http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...

  4. POJ 1036 Rails 模拟堆栈

    水题,主要是思路清晰,判断明确. 记x为A站最前方的车,y表示下一列要进入B站的车厢,初识时,x=1;y=a1;C=[]; 在调度过程中: if(y==0)那么调度成功,退出模拟过程:否则 if(x= ...

  5. POJ 1001 Exponentiation 模拟小数幂

    模拟小数幂 小数点位 pos 非零末位 e 长度 len 只有三种情况 pos > len pos < e e < pos < len #include <iostrea ...

  6. A Simple Problem with Integers POJ - 3468 &lpar;分块&rpar;

    题目链接:https://cn.vjudge.net/problem/POJ-3468 题目大意:区间加减+区间查询操作. 具体思路:本来是一个线段树裸题,为了学习分块就按照分块的方法做吧. 分块真的 ...

  7. POJ 1008 简单模拟题

    e.... 虽然这是一道灰常简单的模拟题.但是米做的时候没有读懂第二个日历的计时方法.然后捏.敲完之后华丽的WA了进一个点.坑点就在一年的最后一天你是该输出本年的.e ...但是我好想并没有..看di ...

  8. poj 1806 Frequent values(RMQ 统计次数) 详细讲解

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1806 题目大意:给你一个非降序排列的整数数组,你的任务是对于一系列的询问,(i,j),回答序列中出现次 ...

  9. Crashing Robots POJ 2632 简单模拟

    Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...

随机推荐

  1. Aspose&period;Cells导出Excel(2)

    DataTable dtTitle = ds.Tables[]; DataTable dtDetail = ds.Tables[]; int columns = dtTitle.Columns.Cou ...

  2. html5 xdm 页面之间的通信

    <!-- 这个是父页面xdm.html --><!DOCTYPE html> <html> <head> <meta charset=" ...

  3. 从MySQL到Redis 提升数据迁移的效率

    场景是从MySQL中将数据导入到Redis的Hash结构中.当然,最直接的做法就是遍历MySQL数据,一条一条写入到Redis中.这样可能没什么错,但是速度会非常慢.而如果能够使MySQL的查询输出数 ...

  4. isIsomorphic

    超时版: /* Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if t ...

  5. php字符串常见面试题

    >> 本文固定链接: http://php.ncong.com/mianshi/mianshiti_string.html >> 转载请注明: 恩聪php 2014年09月02 ...

  6. 【HPP开发】让所有中小企业拥有自己的APP

    HPP hybirdApp或者hbuilderApp, 指通过html,css,js语言开发出ios和android两个版本的APP, 开发效率成倍上升,开发时间大幅缩减,开发成本同样也大大缩减. 移 ...

  7. LR性能测试结果样例分析

    http://www.cnblogs.com/hyzhou/archive/2011/11/16/2251316.html   测试结果分析 LoadRunner性能测试结果分析是个复杂的过程,通常可 ...

  8. h3c acl配置一列

    acl number 3004 rule 0 permit ip source 10.2.1.4 0 rule 1 deny ip source 192.168.1.91 0 rule 2 deny ...

  9. webservice安全性浅谈

    原文地址:http://www.cnblogs.com/chhuic/archive/2009/11/19/1606109.html 做项目时,经常会用到WebService来通讯,但WebServi ...

  10. 手机wap适配

    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scal ...