Codeforces Round #249 (Div. 2)453C Cardiogram(模拟)
来源:互联网 发布:照片排版软件 专业 编辑:程序博客网 时间:2024/05/22 02:19
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 all ai doesn't exceed 1000.
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.
53 1 2 5 1
/ \ / \ / \ / \ / \ \ /
31 5 1
/ \ \ \ \ \ /
这题不就是阅读理解吗。。然而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;}
- Codeforces Round #249 (Div. 2)453C Cardiogram(模拟)
- Codeforces Round #249 (Div. 2)C. Cardiogram
- Codeforces Round #346 (Div. 2) C模拟
- Codeforces Round #325 (Div. 2) C 模拟
- Codeforces Round #316 (Div. 2) C 模拟
- Codeforces Round #306 (Div. 2) C 模拟
- Codeforces Round #126 (Div. 2) C 模拟
- Codeforces Round #373 (Div. 2) C 模拟
- Codeforces Round #377 (Div. 2) C 模拟
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) C 模拟
- Codeforces Round #249 (Div. 2) (模拟)
- Codeforces 435C Cardiogram
- Codeforces 435C. Cardiogram
- CodeForces 435C Cardiogram
- Codeforces 435C Cardiogram
- Codeforces Round #138 (Div. 2) c 数据结构模拟
- Codeforces Round #306 (Div. 2)C. Divisibility by Eight--模拟
- Codeforces Round #283 (Div. 2) C. Removing Columns 模拟+构造
- s3c2440中断总结+按键中断
- Java EE登陆界面生成随机数防止恶意注册或者登录
- jquery.min.map 404的解决办法
- No Dialect mapping for JDBC Type:-9
- leetcode: Merge Sorted Array
- Codeforces Round #249 (Div. 2)453C Cardiogram(模拟)
- 求N!的位数(斯特林公式)
- hdu5410(2015多校10)--CRB and His Birthday(背包问题)
- app store 被拒原因及解决方案(持续更新中)
- 程序RPC 1726错误问题的追踪
- hdu5414
- 骗子
- 黑马程序员-java基础-去除ArrayList中重复的字符串
- 数据库插入datetime数据的java展示