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. CentOS6.5配置MySQL主从同步

    原文地址:http://www.cnblogs.com/zhongshengzhen/   修改主MySQL的配置 [root@localhost etc] vi /etc/my.cnf 添加以下配置 ...

  2. iis启动网站提示 文件正在使用

    通常是端口被占用,使用netstat -ano,查看占用的进程pid,结束

  3. EF中Database.SqlQuery

    本文转载:http://www.cnblogs.com/daimage/archive/2012/07/04/2575844.html EF中Database.SqlQuery<TElement ...

  4. cocos2d-x 纹理深入研究

    转自:http://blog.csdn.net/qq51931373/article/details/9152227 1.纹理控制. 看此代码: CCSprite *pSprite = CCSprit ...

  5. C++多态的实现与局限性

    1.什么是多态? 父类指针指向子类对象,运行时期调用方法的时候,根据方法拥有者的真实类型,确定调用哪个方法. 2.如何实现多态? 要实现多态,需要加一个中间层,暴露父类的方法,内部根据指针的真实类型决 ...

  6. CircularProgressBar

    https://github.com/semicoder/CircularProgressBar https://github.com/amurani/MeterView

  7. android4.4短信新概念

    android4.4对短信引入了一个全新的概念:默认短信应用.即android用户可以在系统设置里面选择一个默认的短信应用,只有这个应用才能进行手机的基本短信操作.按照google自己的解释这样做的原 ...

  8. android学习日记03--常用控件progressbar/seekbar

    常用控件 5.progressbar 进度条,比较常用的组件,在某些操作的进度中的可视指示器,为用户呈现操作的进度,还它有一个次要的进度条,用来显示中间进度,如在流媒体播放的缓冲区的进度.一个进度条也 ...

  9. air 中的 LocalStore

    <ignore_js_op> 在AIR客户端程序中有时需要将用户的一些信息保存在本地,如果信息没有涉及到隐私那么一般用SharedObject类即可将数据存储在本地.由于SharedObj ...

  10. Asp.Net 5使用Area及自定义Area

    Asp.Net Mvc里有一个叫做Area的技术,就是可以把不同逻辑组件的controller, view等放到不同的文件夹里.比如所有管理相关的都放到Admin area里.其实之前我一直对这个功能 ...