Codeforces Round #249 (Div. 2) (模拟)

本博客介绍如何使用C++编程语言通过ASCII字符绘制心电图图形,包括输入序列解析、图形边界设定和输出格式说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C. Cardiogram
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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.

Sample test(s)
Input
5
3 1 2 5 1
Output
      / \     
   / \ /   \    
  /       \   
 /         \  
          \ / 
Input
3
1 5 1
Output
 / \     
  \    
   \   
    \  
     \ / 
Note

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");
	}
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值