Square Ice
Time Limit:1000MS |
|
Memory Limit:10000K |
Total Submissions:3450 |
|
Accepted:1355 |
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*
*******************
#include<iostream>
using namespace std;
#define NUMMAX 100
#define MMAX 15
char arr[NUMMAX][NUMMAX];
int ASM[MMAX][MMAX];
int main(){
int M,i,j,k=1;
while(true){
cin>>M;
for(i=1;i<=M;i++)
for(j=1;j<=M;j++)
cin>>ASM[i][j];
for(i=1;i<=4*M-1;i++){
for(j=1;j<=4*M+3;j++){
if(i==1||i==4*M-1){
arr[i][j]='*';
}else{
if(j==1||j==4*M+3)
arr[i][j]='*';
else if(i%4==0){
if(j%4==0)
arr[i][j]='H';
else
arr[i][j]=' ';
}
else if(i%4==2){
if(j%4==2)
arr[i][j]='H';
else if(j%4==0)
arr[i][j]='O';
else
arr[i][j]=' ';
}
else if(i%2==1){
arr[i][j]=' ';
}
}
}
}
for(i=1;i<=M;i++){
for(j=1;j<=M;j++){
if(ASM[i][j]==0){
if(j==1){
arr[4*i-2][3]='-';
}else{
if(arr[4*i-2][j*4-3]==' ')
arr[4*i-2][j*4-1]='-';
else
arr[4*i-2][j*4+1]='-';
}
if(i==1){
arr[3][4*j]='|';
}else{
if(arr[4*i-5][4*j]=='|')
arr[4*i-1][4*j]='|';
else
arr[4*i-3][4*j]='|';
}
}else if(ASM[i][j]==1){
arr[4*i-2][4*j-1]='-';
arr[4*i-2][4*j+1]='-';
}else if(ASM[i][j]==-1){
arr[4*i-3][4*j]='|';
arr[4*i-1][4*j]='|';
}
}
}
cout<<endl<<"Case "<<k++<<":"<<endl<<endl;;
for(i=1;i<=4*M-1;i++){
for(j=1;j<=4*M+3;j++)
cout<<arr[i][j];
cout<<endl;
}
cout<<endl;
}
}
分享到:
相关推荐
Square
Lesson 8 Tian’anmen Square练习题及答案2.doc
Laravel开发-square Square API与基于Nikolag/Core的Laravel集成
Square Bold Font Type square-721-bold-bt.zip ENCOM Cinema and Video Game Fonts.
系统与软件工程 系统与软件质量要求和评价(SQuaRE) 第1部分:SQuaRE指南.pdf
python opencv square
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square ...
Hanover Square 汉诺威广场--- 追忆似水年华
ZJU_Main 主页 下一页 ZJU 题型分类 文演整理版 2008-3-23 数论: 1007 Numerical Summation of a Series 简单题,还是蛮有意思的 ... 1066 Square Ice 无聊题,目前已知的O(nlogn)算法要用AVL ...
Square root
ISO_IEC 25000-2014 (SQuaRE) — Guide to SQuaRE.pdf
square
Square_ONE 图示均衡器 效果器 压限器
Android应用源码之android-times-square Android日历部件.zip
non_linear least square problems 非线性优化讲解的比较好的资料
Square源码,是一个很不错的Android代码,有兴趣的伙伴们抽时间可以看一下把。
Minimum mean square error method for stripe nonuniformity correction 是关于红外图像非均匀性校正的论文