In this problem, your task is to use ASCII graphics to paint a cardiogram.
A cardiogram is a polyline with the following corners:
That is, a cardiogram is fully defined by a sequence of positive integers a1, a2, ..., an.
Your task is to paint a cardiogram by given sequence ai.
The first line contains integer n (2 ≤ n ≤ 1000). The next line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 1000). It is guaranteed that the sum of all ai doesn't exceed 1000.
Print max |yi - yj| lines (where yk is the y coordinate of the k-th point of the polyline), in each line print characters. Each character must equal either « / » (slash), « \ » (backslash), « » (space). The printed image must be the image of the given polyline. Please study the test samples for better understanding of how to print a cardiogram.
Note that in this problem the checker checks your answer taking spaces into consideration. Do not print any extra characters. Remember that the wrong answer to the first pretest doesn't give you a penalty.
5 3 1 2 5 1
/ \ / \ / \ / \ / \ \ /
3 1 5 1
/ \ \ \ \ \ /
Due to the technical reasons the answers for the samples cannot be copied from the statement. We've attached two text documents with the answers below.
http://assets.codeforces.com/rounds/435/1.txt
http://assets.codeforces.com/rounds/435/2.txt
题目链接:http://codeforces.com/problemset/problem/435/C
题目大意:打印如图所看到的的图案,開始图形斜上。
解题思路:数组存储模拟。数组大小2000*2000。横坐标从1000处開始模拟。
初始化全部字符为空格,标记每条坡的最高值和最低值。这里最高和最低反过来思考,由于打印时是从上往下的,即上面是坡的低值。以下是坡的高值。第奇数个坡是上升的,次对角线时字符为‘/’,第偶数个坡值是下降的,主对角线上字符为'\',(注意,打印时这样输出‘\\’),找到整个图形横坐标的最大值和最小值,即横坐标的范围,就能输出整个图形了。
代码例如以下:
#include <cstdio> #include <cstring> int const maxn=2005; char eg[maxn][maxn]; int a[maxn],hg[maxn],lw[maxn]; int main() { int n; scanf("%d",&n); int ma=1000,mi=1000; //整个图形的最高点和最低点 hg[0]=1000; for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) eg[i][j]=' '; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); if(i%2==0) //记录每条坡值的最高点和最低点 { lw[i]=lw[i-1]; hg[i]=lw[i]+a[i]; if(ma<hg[i]) ma=hg[i]; } else { hg[i]=hg[i-1]; lw[i]=hg[i]-a[i]; if(mi>lw[i]) mi=lw[i]; } } int x=0; //标记每条坡開始的纵坐标 for(int i=1;i<=n;i++) { if(i%2==0) { for(int k=lw[i];k<hg[i];k++) for(int j=x;j<x+a[i];j++) if(j-x==k-lw[i]) //主对角线上 eg[k][j]='\\'; } else { for(int k=lw[i];k<hg[i];k++) for(int j=x;j<x+a[i];j++) if(j-x==a[i]-k+lw[i]-1) //次对角线上 eg[k][j]='/'; } x+=a[i]; } for(int i=mi;i<ma;i++) //横坐标从mi到ma { for(int j=0;j<x;j++) printf("%c",eg[i][j]); printf("\n"); } }