Codeforces Round #249 (Div. 2) (模拟)
来源:互联网 发布:mysql系统表 编辑:程序博客网 时间:2024/06/03 21:01
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.
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 allai doesn't exceed1000.
Print max |yi - yj| lines (whereyk is they 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.
53 1 2 5 1
/ \ / \ / \ / \ / \ \ /
31 5 1
/ \ \ \ \ \ /
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) (模拟)
- Codeforces Round #355 (Div. 2)(模拟)
- Codeforces Round #346 (Div. 2) -A. Round House(模拟)
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes(模拟)
- Codeforces Round #249 (Div. 2)453C Cardiogram(模拟)
- Codeforces Beta Round #96 (Div. 2) (模拟)
- Codeforces Round #256 (Div. 2) B. Suffix Structures(模拟)
- Codeforces Round #107 (Div. 2) A(简单模拟)
- Codeforces Round #107 (Div. 2) B (简单模拟)
- Codeforces Round #109 (Div. 2) A (简单模拟)
- Codeforces Round #265 (Div. 2) B. Inbox (100500)(模拟)
- Codeforces Round #281 (Div. 2)A(构造+暴力模拟)
- Codeforces Round #294 (Div. 2) D (模拟)
- Codeforces Round #295 (Div. 2) -- B. Two Buttons (模拟)
- Codeforces Round #149 (Div. 2) Dispute (队列+容器模拟)
- C. Replacement( Codeforces Round #316 (Div. 2) 模拟)
- Codeforces Round #316 (Div. 2) C. Replacement (模拟)
- Codeforces Round #316 (Div. 2) B. Simple Game (模拟)
- Android SDK下载和更新失败的解决方法
- HDU 5391 Zball in Tina Town(不知道的定理)
- 线性(一般性)拟合最小二乘解(超定方程)
- ubuntu 12.04 安装 Cloudera Manager5及CDH5(Mysql)【添加yum源方式安装集群】
- Sentry Robots
- Codeforces Round #249 (Div. 2) (模拟)
- 重建二叉树
- [搜索]poj1011
- oracle创建存储函数:查询某个员工的年收入
- POJ 2828 Buy Tickets(线段树)
- Hibernate的generator属性的意义
- lintcode Interval Sum
- Java的数据类型和运算符
- 实现自己的类加载时,重写方法loadClass与findClass的区别