CF 345 C 模拟
2016-05-02 15:29
330 查看
http://codeforces.com/contest/435/problem/C
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:
![](http://codeforces.com/predownloaded/1f/d8/1fd812004790ee59674b9bd2d544faab1538013e.png)
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
![](http://codeforces.com/predownloaded/47/21/47213d6fb6ce08927d970b3abed013baa916a684.png)
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.
Examples
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
题目大意:
模拟心电图
思路:
感觉找规律就好了。自己画一下图,标一下号就出来了(表示调试了半天,罪过罪过)
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:
![](http://codeforces.com/predownloaded/1f/d8/1fd812004790ee59674b9bd2d544faab1538013e.png)
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
![](http://codeforces.com/predownloaded/47/21/47213d6fb6ce08927d970b3abed013baa916a684.png)
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.
Examples
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
题目大意:
模拟心电图
思路:
感觉找规律就好了。自己画一下图,标一下号就出来了(表示调试了半天,罪过罪过)
#include using namespace std; const int maxn = 1000 + 5; const int inf = 0x3f3f3f3f; struct point{ int x, y; }; point p[maxn]; int n; int mx, my; int atlas[maxn][maxn]; void solve(){ memset(atlas, 0, sizeof(atlas)); int x = p[0].x, y = p[0].y; for (int i = 1; i <= n; i++){ int nx = p[i].x; int ny = p[i].y; //0为空格,-1为/,1为右偏 if (ny > y){ for (int i = x, j = y; i < nx, j < ny; i++, j++){ atlas[j][i] = -1; /*printf("check1\n"); printf("atlas[%d][%d] = %d\n", j, i, atlas[j][i]);*/ } } else if (ny < y){ for (int i = x, j = y-1; i < nx, j >= ny; i++, j--){ atlas[j][i] = 1; /*printf("check2\n"); printf("atlas[%d][%d] = %d\n", j, i, atlas[j][i]);*/ } } x = nx, y = ny; } /* printf("check\n"); for (int i = my - 1; i >= 0; i--){ for (int j = 0; j < mx; j++){ printf("%d%c", atlas[i][j], j == mx-1 ? '\n' : ' '); } } printf("mx = %d my = %d\n", mx, my); */ for (int i = my-1; i >= 0; i--){ for (int j = 0; j < mx; j++){ //printf("i = %d j = %d\n", i, j); if (atlas[i][j] == 0) printf(" "); else if (atlas[i][j] == -1) printf("%c", 47); else if (atlas[i][j] == 1) printf("%c", 92); } printf("\n"); } } int main(){ scanf("%d", &n); int tmp = inf; int x = 0, y = 0; p[0].x = 0, p[0].y = 0; int a; for (int i = 1; i <= n; i++){ scanf("%d", &a); x += a; if (i % 2 == 1) y += a; else y -= a; p[i].x = x, p[i].y = y; tmp = min(tmp, min(x, y)); } if (tmp < 0){ tmp = -tmp; for (int i = 0; i <= n; i++){ p[i].y += tmp; } } for (int i = 0; i <= n; i++){ mx = max(p[i].x, mx); my = max(p[i].y, my); } solve(); return 0; }
相关文章推荐
- 《More Effective C++》读书笔记-技术(二)
- postgresql9.5 run 文件linux安装后配置成开机服务
- POJ 2605 数学
- 图形绘制管线
- Spark-Avro学习8之Java Avro使用(不生成code方式)
- POJ 3264 RMQ—ST
- Android Studio 下的NDK环境搭建与JNI调用
- POJ 1555 Polynomial Showdown(字符串模拟)
- 51node1091 线段的最长交集(贪心)
- 性能测试定义
- hdu 1025 Constructing Roads In JGShining's Kingdom
- Java中final关键字的用法
- Is the server running on host “localhost” (::1) and accepting TCP/IP connections on port 5432?
- 解决使用pip安装lxml包报错问题
- JS学习6(函数表达式)
- 用HTML 5实现爱心小鱼的游戏
- 定量分析与print跟踪在代码分析中的运用
- 开源新闻速递(160502):Arch Linux 2016.05.01 发布
- 48-Merge Sorted Array
- 学生信息管理系统总结整理