标签:span har 啊啊啊 paint 通过 因此 positive NPU clu
A cardiogram is a polyline with the following corners:
\((0;0), (a_1;a_1), (a_1+a_2;a_1-a_2),...,(\sum_{i=1}^n{a_i};\sum_{i=1}^n{(-1)^{i+1}a_i})\)
That is, a cardiogram is fully defined by a sequence of positive integers \(a_1,?a_2,?...,?a_n\).
Your task is to paint a cardiogram by given sequence \(a_i\).
Input
The first line contains integer n (2?≤?n?≤?1000). The next line contains the sequence of integers a 1,?a 2,?...,?a n (1?≤?a i?≤?1000). It is guaranteed that the sum of all a i doesn‘t exceed 1000.
Output
Print \(max |y_i?-?y_j|\) lines (where y k 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.
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1005;
int n;
typedef pair<int,int> pa;
pa a[MAXN];
int main(){
// freopen("out.txt","w",stdout);
scanf("%d",&n);
int sumx=0,sumy=0;
int mxy=0,mny=0;
int t;
a[0]=make_pair(0,0);
for(int i=1;i<=n;i++)
{
scanf("%d",&t);
sumx+=t;
if(i&1)
sumy+=t;
else sumy-=t;
a[i]=make_pair(sumx,sumy);
mxy=mxy<sumy?sumy:mxy;
mny=mny>sumy?sumy:mny;
}
for(int i=mxy;i>=mny;i--){
for(int j=0;j<n;j++){
if(a[j].second<=i&&a[j+1].second>=i){
int difY = a[j+1].second-a[j].second;
int difX = a[j+1].first-a[j].first;
for(int z=1;z<=difX;z++){
if(z==(i-a[j].second))
printf("/");
else printf(" ");
}
}
else if(a[j].second>=i&&a[j+1].second<=i){
int difY = a[j].second-a[j+1].second;
int difX = a[j+1].first-a[j].first;
for(int z=0;z<difX;z++){
if(z==(a[j].second-i))
printf("\\");
else printf(" ");
}
}
else{
for(int z=a[j].first;z<a[j+1].first;z++) printf(" ");
}
}
printf("\n");
}
return 0;
}
标签:span har 啊啊啊 paint 通过 因此 positive NPU clu
原文地址:https://www.cnblogs.com/xuwanwei/p/12831459.html