Codeforces Round #249 (Div. 2)453C Cardiogram(模拟)

本文介绍了一种使用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
 / \     
  \    
   \   
    \  
     \ / 



这题不就是阅读理解吗。。然而6级还是挂了闭嘴 奇数的时候向上输出,偶数的时候向下输出。字符数组开大些,还要存空格。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int MAXN = 1100;
int n, x, y, up, down, a[MAXN];
char map[MAXN][MAXN];
int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		x += a[i];
		if(i % 2 == 0) y += a[i];
		else y -= a[i];
		up = max(y, up);
		down = min(y, down);
	}
	int num = x;
	x = up, y = 0;
	memset(map, ' ', sizeof(map));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < a[i]; ++j)
			if(i % 2 == 0) {
				map[x][y] = '/';
				x--, y++;
			}
			else {
				map[x][y] = '\\';
				x++, y++;
			}
		if(i % 2 == 0) x++;
		else x--;
	}
	for(int i = 1; i <= up - down; ++i) {
		for(int j = 0; j < num; ++j)
			printf("%c", map[i][j]);
		printf("\n");
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值