CF 345 C 模拟

1 篇文章 0 订阅

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:

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.

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;
}
   
   

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值