模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

 

题目地址:http://codeforces.com/contest/435/problem/C

 1 /*
 2     题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:)
 3     模拟题:蛮恶心的,不过也简单,依据公式得知折线一定是一上一下的,只要把两个相邻的坐标之间的折线填充就好
 4     注意:坐标有可能为负数,所以移动值y初始化为1000,最后要倒过来输出
 5     详细解释:http://blog.csdn.net/zhb1997/article/details/27877783
 6 */
 7 #include <cstdio>
 8 #include <iostream>
 9 #include <algorithm>
10 #include <cstring>
11 #include <string>
12 #include <cmath>
13 #include <set>
14 using namespace std;
15 
16 const int MAXN = 1e3 + 10;
17 const int INF = 0x3f3f3f3f;
18 int map[MAXN<<1][MAXN<<1];
19 int a[MAXN];
20 
21 int main(void)        //Codeforces Round #249 (Div. 2) C. Cardiogram
22 {
23     //freopen ("G.in", "r", stdin);
24 
25     int n;
26     while (~scanf ("%d", &n))
27     {
28         int tot = 0;    int mx = 1000, mn = 1000, x = 0, y = 1000;
29         for (int i=1; i<=n; ++i)    scanf ("%d", &a[i]), tot += a[i];
30 
31         memset (map, 0, sizeof (map));
32         for (int i=1; i<=n; ++i)
33         {
34             x++;
35             if (i & 1)        //奇数一定'/'
36             {
37                 a[i]--;
38                 map[y][x] = 1;
39                 while (a[i]--)
40                 {
41                     x++;    y++;
42                     map[y][x] = 1;
43                 }
44                 mx = max (mx, y);
45             }
46             else        //偶数一定'\'
47             {
48                 a[i]--;
49                 map[y][x] = 2;
50                 while (a[i]--)
51                 {
52                     x++;    y--;
53                     map[y][x] = 2;
54                 }
55                 mn = min (mn, y);
56             }    
57         }
58 
59         //printf ("%d %d\n", mx, mn);
60         for (int i=mx; i>=mn; --i)        //y坐标
61         {
62             for (int j=1; j<=tot; ++j)    //x坐标
63             {
64                 if (map[i][j] == 1)    printf ("/");
65                 else if (map[i][j] == 2)    printf ("\\");
66                 else    printf (" ");
67             }
68             puts ("");
69         }
70     }
71 
72     return 0;
73 }

 

posted @ 2015-04-01 19:48  Running_Time  阅读(143)  评论(0编辑  收藏  举报