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. Winform- TreeView的使用例子

    自动递归生成树,点击树节点的事件在treeView1_AfterSelect里编写,不多说了,直接上代码,备注在这里一下 public partial class Form1 : Form { pub ...

  2. Spider Studio 数据挖掘集成开发环境

    (最新版本: 2.7.12.1) 传统的多线程蜘蛛程序虽然采集速度快, 但是明明不需要所有内容, 却胡子眉毛一把抓, 将整个网页都下载下来当作一个文本进行处理. 由于网页内容参差不齐, 所以抓取质量常 ...

  3. iOS开发-在表单元中添加子视图

    #import <UIKit/UIKit.h> @interface NameAndColorCellTableViewCell : UITableViewCell @property(c ...

  4. ssh免密码登录记录

    做mha.hadoop安装过程中都要用ssh免密码登陆,查过一些资料,踩过很多坑,下面用简单记录一下 首先要安装ssh linux : centOS 6.5 yum -y install *ssh* ...

  5. Redis实战之征服 Redis + Jedis + Spring (二)

    不得不说,用哈希操作来存对象,有点自讨苦吃! 不过,既然吃了苦,也做个记录,也许以后API升级后,能好用些呢?! 或许,是我的理解不对,没有真正的理解哈希表. 相关链接: Redis实战 Redis实 ...

  6. Oracle用户及角色的权限管理[Oracle基础]

    1.查看全部用户:   select * from dba_users;   select * from all_users;   select * from user_users; 2.查看用户或角 ...

  7. js replace如何实现全部替换

    js中replace默认只替换第一个相关字符,要想实现替换全部相关字符.如下: replace(/*/g, ','); 例如,替换字符串中的\n str.replace(/\n/g, ',');

  8. [Sciter系列] MFC下的Sciter–1.创建工程框架

      Sciter SDK中提供的Win32下例程很多,唯独使用很多(对我个人而言)的MFC框架下Sciter程序的构建讲的很少,虽然MFC有这样那样的诟病,但是不可否认的是编写一般的小项目,这仍然是大 ...

  9. 接入新浪、腾讯微博和人人网的Android客户端实例 接入新浪、腾讯微博和人人网的Android客户端实例

    做了个Android项目,需要接入新浪微博,实现时也顺带着研究了下腾讯微博和人人网的Android客户端接入,本文就跟大家分享下三者的Android客户端接入方法. 一.实例概述 说白了,接入微博就是 ...

  10. SAP ABAP MARD和MARDH计算逻辑

    mard里记载的是当前库存的数量,但是期间并不一定是当月.比如你物料4月一整月都没有库存数量变化(没收没发),那么5月初你看mard里的条目期间数还是4月而非5月. 当某个期间发生货物移动的时候,系统 ...