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. C语言 将十六进制字符串转为十六进制数 (二进制、十进制都适用)

    主要利用 long int strtol(const char *nptr,char **endptr,int base); 函数 函数说明: 参数base范围从2至36,或0.参数base代表采用的 ...

  2. MyBatis初始化

    1. 准备工作 为了看清楚MyBatis的整个初始化过程,先创建一个简单的Java项目,目录结构如下图所示: 1.1 Product 产品实体类 public class Product { priv ...

  3. jquery访问ashx文件示例

    转自原文jquery访问ashx文件示例 .ashx 文件用于写web handler的..ashx文件与.aspx文件类似,可以通过它来调用HttpHandler类,它免去了普通.aspx页面的控件 ...

  4. HDU 1131

    N个节点的不同的树的数目.这样 随便取一个节点作为根,那么他左边和右边的儿子节点个数就确定了,假定根节点标号为x,那么左子树的标号就从1到x-1,共x-1个,右子树的标号就从x+1到n,共n-x个,那 ...

  5. 一起talk C栗子吧(第一百一十二回:C语言实例--线程同步概述)

    各位看官们,大家好.上一回中咱们说的是线程间通信的样例,这一回咱们说的样例是:线程同步.闲话休提,言归正转.让我们一起talk C栗子吧! 看官们,提到同步.我想大家都不陌生,由于我们在前面章回中介绍 ...

  6. Cocos2d-x 多点触摸

    多点触摸的实现步骤与单点触摸类似,setTouchEnabled(true)开启触摸功能,注冊触摸事件,重载多点触摸函数:ccTouchesBegan(開始).ccTouchesMoved(移动).c ...

  7. android drawable资源调用使用心得

    1. 调用顺序 android 调用应用图片资源时,会优先选择当前手机屏幕dpi对应的的文件夹(如drawable-ldpi, drawable-mdpi, drawable-hdpi, drawab ...

  8. iOS对象方法和类方法的区别与调用方式

    作为一个iOS程序员初学者,会搞不清楚对象方法和类方法的区别 -(void)duixiangfangfa ; +(void)leifangfa; - 代表实例方法,它在类的一个具体实例范围内执行,也就 ...

  9. m_Orchestrate learning system---二十一、怎样写算法比较轻松

    m_Orchestrate learning system---二十一.怎样写算法比较轻松 一.总结 一句话总结:(1.写出算法步骤,这样非常有利于理清思路,这样就非常简单了 2.把问题分细,小问题用 ...

  10. mount ntfs 失败解决办法

    在双系统中,ntfs可能会应为windows的缓存而挂载失败.可用下面命令修复. Use ntfsfix in the terminal, even if you can't access Windo ...