Codeforces Round #249 (Div. 2) (模拟)
2015-08-17 23:56
591 查看
[align=center]C. Cardiogram[/align]
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
Output
Input
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处开始模拟。初始化所有字符为空格,标记每条坡的最高值和最低值,这里最高和最低反过来思考,因为打印时是从上往下的,即上面是坡的低值,下面是坡的高值。第奇数个坡是上升的,次对角线时字符为‘/’,第偶数个坡值是下降的,主对角线上字符为'\',(注意,打印时这样输出‘\\’),找到整个图形横坐标的最大值和最小值,即横坐标的范围,就能输出整个图形了。
代码如下:
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"); } }
相关文章推荐
- C/C++获取本地时间常见方法
- Centos 6.4 KVM安装和配置
- Android 双进程Service常驻后台,无惧“一键清理
- apache和IIS同时存在,apache建立多个网站
- Codeforces Gym 100431B Binary Search 搜索+组合数学+高精度
- JQuery学习笔记 选择器 序
- XML报错
- javascript
- 《Java解惑》读书笔记
- CSU 1542 Flipping Parentheses(线段树)
- Java设计思想(1)
- Java基础---面向对象
- 手把手实现andriod应用增量升级
- hdu 1166 敌兵布阵
- JavaScript权威指南_156_第16章_脚本化CSS_16.6-脚本化样式表
- nslookup工具
- Mac OS安装使用docker
- nginx环境配置
- shell 脚本教程--入门级
- hello world!