Square Ice

Description

Square Ice is a two-dimensional arrangement of water molecules H2O, with oxygen at the vertices of a square lattice and one hydrogen atom between each pair of adjacent oxygen atoms. The hydrogen atoms must stick out on the left and right sides but are not allowed to stick out the top or bottom. One 5 x 5 example is shown below. 

Note that each hydrogen atom is attached to exactly one of its neighboring oxygen atoms and each oxygen atom is attached to two of its neighboring hydrogen atoms. (Recall that one water molecule is a unit of one O linked to two H's.)

It turns out we can encode a square ice pattern with what is known as an alternating sign matrix (ASM): horizontal molecules are encoded as 1, vertical molecules are encoded as -1 and all other molecules are encoded as 0. So, the above pattern would be encoded as: 

An ASM is a square matrix with entries 0, 1 and -1, where the sum of each row and column is 1 and the non-zero entries in each row and in each column must alternate in sign. (It turns out there is a one-to-one correspondence between ASM's and square ice patterns!)

Your job is to display the square ice pattern, in the same format as the example above, for a given ASM. Use dashes (-) for horizontal attachments and vertical bars (|) for vertical attachments. The pattern should be surrounded with a border of asterisks (*), be left justified and there should be exactly one character between neighboring hydrogen atoms (H) and oxygen atoms (O): either a space, a dash or a vertical bar.

Input

Input consists of multiple cases. Each case consists of a positive integer m (<= 11) on a line followed by m lines giving the entries of an ASM. Each line gives a row of the ASM with entries separated by a single space. The end of input is indicated by a line containing m = 0.

Output

For each case, print the case number (starting from 1), in the format shown in the Sample Output, followed by a blank line, followed by the corresponding square ice pattern in the format described above. Separate the output of different cases by a blank line.

Sample Input

2
0 1
1 0
4
0 1 0 0
1 -1 0 1
0 0 1 0
0 1 0 0
0

Sample Output

Case 1:

***********
*H-O H-O-H*
* | *
* H H *
* | *
*H-O-H O-H*
*********** Case 2: *******************
*H-O H-O-H O-H O-H*
* | | | *
* H H H H *
* | *
*H-O-H O H-O H-O-H*
* | | *
* H H H H *
* | | *
*H-O H-O H-O-H O-H*
* | *
* H H H H *
* | | | *
*H-O H-O-H O-H O-H*
*******************

题目大意:模拟

分析: 1.1个'O'连接2个'H',1个'H'只连接1个'O'

    2.初始化不可以用memset(map,0,sizeof(map)) 应该初始化为空格

    3.1对应两个'-',-1对应两个'|',0必须对应一个'-'和一个'|'

    4.模拟题目尽量少开flag标记,容易出错又不好检查出来,尽量按照正常思维模拟。

代码如下:

 # include <iostream>
# include<cstdio>
# include<cstring>
# include<cmath>
using namespace std;
char map[][];
int s[][]; bool judge(int i,int j)
{
if(map[i-][j]=='|'||map[i+][j]=='|'||map[i][j-]=='-'||map[i][j+]=='-')
return false;
return true;
} int main()
{
int T,cas=,i,j,n,a,b;
while(scanf("%d",&n) && n)
{
for(i=; i<n; i++)
for(j=; j<n; j++)
scanf("%d",&s[i][j]);
int y = *n+;
int x = *n-;
for(i=; i<=x; i++)
for(j=; j<=y; j++)
map[i][j] = ' '; for(i=; i<x; i++)
map[i][] = map[i][y-] = '*';
for(j=; j<y; j++)
map[][j] = map[x-][j] = '*'; for(i=; i<=x-; i+=)
{
for(j=; j<=y-; j+=)
map[i][j] = 'H';
for(j=; j<=y-; j+=)
map[i][j] = 'O';
}
for(i=; i<=x-; i+=)
{
for(j=; j<=y-; j+=)
map[i][j] = 'H';
} for(i=; i<n; i++)
{
a = i*+;
for(j=; j<n; j++)
{
b= j*+;
if(s[i][j] == )
{
map[a][b-] = '-';
map[a][b+] = '-';
}
else if(s[i][j] == -)
{
map[a+][b] = '|';
map[a-][b] = '|';
}
}
} for(i=; i<n; i++)
{
for(j=; j<n; j++)
{
if(s[i][j]==)
{
a = i*+;
b= j*+;
if(judge(a,b-))
map[a][b-] = '-';
else
map[a][b+] = '-';
if(a->&&judge(a-,b))
map[a-][b] = '|';
else
map[a+][b] = '|';
}
}
} printf("Case %d:\n\n",cas++);
for(i=; i<x; i++)
{
for(j=; j<y; j++)
{
printf("%c",map[i][j]);
}
printf("\n");
}
printf("\n");
}
return ;
}

POJ 1099 Square Ice的更多相关文章

  1. POJ 1099 Square Ice 连蒙带猜+根据样例找规律

    目录 题面 思路 思路 AC代码 题面 Square Ice Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4526   A ...

  2. [ACM_其他] Square Ice (poj1099 规律)

    Description Square Ice is a two-dimensional arrangement of water molecules H2O, with oxygen at the v ...

  3. DFS POJ 2362 Square

    题目传送门 /* DFS:问能否用小棍子组成一个正方形 剪枝有3:长的不灵活,先考虑:若根本构不成正方形,直接no:若第一根比边长长,no 这题是POJ_1011的精简版:) */ #include ...

  4. poj 1099

    http://poj.org/problem?id=1099 #include<stdio.h> #include<string.h> #include <iostrea ...

  5. (中等) POJ 1084 Square Destroyer , DLX+可重复覆盖。

    Description The left figure below shows a complete 3*3 grid made with 2*(3*4) (=24) matchsticks. The ...

  6. POJ 2362 Square DFS

    传送门:http://poj.org/problem?id=2362 题目大意: 给一些不同长度的棍棒,问是否可能组成正方形. 学习了写得很好的dfs 赶紧去玩博饼了.....晚上三个地方有约.... ...

  7. POJ 2362 Square

    题意:给n个木棍,问能不能正好拼成一个正方形. 解法:POJ1011的简单版……不需要太多剪枝……随便剪一剪就好了……但是各种写屎来着QAQ 代码: #include<stdio.h> # ...

  8. [DLX反复覆盖] poj 1084 Square Destroyer

    题意: n*n的矩形阵(n<=5),由2*n*(n+1)根火柴构成,那么当中会有非常多诸如边长为1,为2...为n的正方形,如今能够拿走一些火柴,那么就会有一些正方形被破坏掉. 求在已经拿走一些 ...

  9. POJ题目排序的Java程序

    POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...

随机推荐

  1. Oracle-12541:TNS:无监听程序 .

    背景:自己机子做oracle服务器,其他机子可以ping得通我的机子,但是jdbc就是连不上,后来用plsql连出现无监听程序.... 我昨天重新安装Oracle后,用PL/SQL Developer ...

  2. jQuery插件- Autocomplete应用详解

    项目中有时会用到自动补全查询,就像Google搜索框.淘宝商品搜索功能,输入汉字或字母,则以该汉字或字母开头的相关条目会显示出来供用户选择, autocomplete插件就是完成这样的功能. auto ...

  3. Android短彩信源码解析-短信发送流程(三)

    3.短信pdu的压缩与封装 相关文章: ------------------------------------------------------------- 1.短信发送上层逻辑 2.短信发送f ...

  4. int、bigint、smallint 和 tinyint

    Transact-SQL 参考 int.bigint.smallint 和 tinyint 使用整数数据的精确数字数据类型. bigint 从 -2^63 (-9223372036854775808) ...

  5. Nuget控制台 - 给你的快速添加缺少的包

    利用命令行安装包

  6. js 如何将无限级分类展示出来

    这个需要运用递归. 案例:将数据以 ul li ul li形式展现在div中. <div id="div"></div> 数据格式为json: var da ...

  7. Codeforces Round #200 (Div. 1) C. Read Time 二分

    C. Read Time Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343/problem/C ...

  8. redis实现spring-redis-data的入门实例

    redis的客户端实现.主要分为spring-redis-data .jredis. 记录下spring-redis-data的学习心得:spring-redis-data 中我目前主要用了它的存.取 ...

  9. pomelo 开发环境搭建

    开发前提条件:  Windows系统,请确保你的Windows系统包括源代码编译工具.Node.js的源代码主要由C++代码和JavaScript代码构成,可是却用gyp工具来做源代码的项目管理,该工 ...

  10. linux 内核之旅

    http://www.kerneltravel.net/?p=534 http://mp.weixin.qq.com/mp/homepage?__biz=MzI3NzA5MzUxNA==&hi ...