概述
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
有些坑。。。
注意每行要填满,最大的x个字符
就是可能要用空格填坑
这次大概用了一个小时才有思路,
就是维护一个堆,画图
中途写好之后发现不能把/跟同样处理
之后又发现每行还要填坑。。。
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
struct st
{
int x,y;
int flag;
st(){}
st(int x,int y,int flag)
{
this->x=x;
this->y=y;
this->flag=flag;
}
bool operator <(st one)const
{
if(y!=one.y)
return y<one.y;
return x>one.x;
}
};
int main()
{
int n;
cin>>n;
int x=0,y=0;
priority_queue<st>qq;
set<st>vis;
vis.insert(st(x,y,1));
for(int i=0;i<n;i++)
{
int t;
cin>>t;
x+=t;
if(i%2==0)
{
y+=t;
if(i!=n-1)
qq.push(st(x,y,1));
else
qq.push(st(x,y,3));
}
else
{
y-=t;
vis.insert(st(x,y,1));
}
}
int px=0,py=qq.top().y;
while(qq.size())
{
st t=qq.top();
qq.pop();
if(vis.count(st(t.x,t.y,1)))
continue;
if(t.y!=py)
{
printf("%*sn",x-px,"");
px=0;
py=t.y;
}
if(t.flag==0)
{
printf("%*c",t.x-px,'/');
px=t.x;
qq.push(st(t.x-1,t.y-1,0));
}
else if(t.flag==2)
{
printf("%*c",t.x-px+1,92);
px=t.x+1;
qq.push(st(t.x+1,t.y-1,2));
}
else
{
printf("%*c",t.x-px,'/');
px=t.x;
qq.push(st(t.x-1,t.y-1,0));
if(t.flag!=3)
{
putchar(92);
px=t.x+1;
qq.push(st(t.x+1,t.y-1,2));
}
}
}
printf("%*sn",x-px,"");
}
最后
以上就是安详酸奶为你收集整理的Codeforces Round #249 (Div. 2)C. Cardiogram的全部内容,希望文章能够帮你解决Codeforces Round #249 (Div. 2)C. Cardiogram所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复