http://codeforces.com/contest/435/problem/C
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.
5 3 1 2 5 1
/ \ / \ / \ / \ / \ \ /
3 1 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
题目大意:
模拟心电图
思路:
感觉找规律就好了。自己画一下图,标一下号就出来了(表示调试了半天,罪过罪过)
#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;
}