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

Codeforces Round #249 (Div. 2) (模拟)的更多相关文章

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

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

  2. Codeforces Round #249 (Div. 2) C题,模拟画图 ----未解决!

    http://codeforces.com/contest/435/problem/C

  3. Codeforces Round #249 (Div. 2) 总结

    D.E还是很难的.....C不想多说什么... A:提意:给出每一组人的个数,以及一次车载容量,求出最少需要多少次才能载走所有的人. water: http://codeforces.com/cont ...

  4. Codeforces Round #249 (Div. 2)B(贪心法)

    B. Pasha Maximizes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. Codeforces Round #249 (Div. 2) A题

    链接:http://codeforces.com/contest/435/problem/A   A. Queue on Bus Stop time limit per test 1 second m ...

  6. Codeforces Round #249 (Div. 2) D. Special Grid 枚举

    题目链接: http://codeforces.com/contest/435/problem/D D. Special Grid time limit per test:4 secondsmemor ...

  7. Codeforces Round #249 (Div. 2) A B

    C好像就是个模拟.D 是个编码复杂度大的,可是好像也就是枚举三角形,我这会儿准备区域赛,尽量找点思维难度大的,所以昨晚A B 还是去做区域赛题吧..... B 也有点意思 贪心 题意:交换相邻两个位的 ...

  8. Codeforces Round #382 (Div. 2) (模拟|数学)

    题目链接: A:Ostap and Grasshopper B:Urbanization C:Tennis Championship D:Taxes 分析:这场第一二题模拟,三四题数学题 A. 直接模 ...

  9. Codeforces Round #249 (Div. 2) C. Cardiogram

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

随机推荐

  1. 小白神器 - 两篇博客读懂JavaScript (一基础篇)

    JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理. 一. 编写格式 1, ...

  2. Docker决战到底(三) Rancher2.x的安装与使用 - 简书

    原文:Docker决战到底(三) Rancher2.x的安装与使用 - 简书   image.png 当越来越多的容器化应用被部署,一个可以管理编排这些容器的工具此时就显得尤为重要了.目前容器编排领域 ...

  3. 异构关系数据库(Sqlserver与MySql)之间的数据类型转换参考

    一.SqlServer到MySql的数据类型的转变 编号 SqlServer ToMySql MySql 1 binary(50) LONGBLOB binary 2 bit CHAR(1) bit ...

  4. 基本配置及安全级别security-level

    interface GigabitEthernet0/0 nameif outside  //指定接口名称 security-level 0  //安全级别设置 ip address 1.1.1.2 ...

  5. 关于VMNet1、VMNet8、

    关于vmnet1~~~~~vmnet8 2008年04月11日 星期五 23:18 先说vmnet0,实际上就是一个虚拟的网桥,这个网桥有很若干个端口,一个端口用于连接你的Host,一个端口用于连接你 ...

  6. Non-ASCII character &#39;\xe8&#39; in file xxx.py on line 8, but no encoding declared

    使用网上某个python程序.编译时报错: File "xxx.py", line 8         SyntaxError: Non-ASCII character '\xe8 ...

  7. c语言运算符优先级与while循环案例

    sizeof可以获取数据类型的内存中的大小(字节) #include <stdio.h> #include <stdlib.h> // standared 标准 // inpu ...

  8. python+caffe训练自己的图片数据流程

    1. 准备自己的图片数据 选用部分的Caltech数据库作为训练和测试样本.Caltech是加州理工学院的图像数据库,包含Caltech101和Caltech256两个数据集.该数据集是由Fei-Fe ...

  9. ShellExcuteA

    ShellExecuteA(,//0表示系统打开 "open",//操作 "1.mp3",//操作路径 0,//第四个,第五个参数都是保留参数,默认都为0 0, ...

  10. MYSQL 5.7 MHA(GTID+ROW)部署及failover,online_change实战演练

    文章结构如下: 1.MHA简介 Masterhigh availability manager and toolsfor mysql,是日本的一位mysql专家采用perl语言编写的一个脚本管理工具, ...