Codeforces---Mountain Scenery
来源:互联网 发布:淘宝买家号快速升级 编辑:程序博客网 时间:2024/05/02 07:55
题目链接: http://codeforces.com/problemset/problem/218/A
Little Bolek has found a picture with n mountain peaks painted on it. The n painted peaks are represented by a non-closed polyline, consisting of 2n segments. The segments go through 2n + 1 points with coordinates (1, y1), (2, y2), ..., (2n + 1, y2n + 1), with the i-th segment connecting the point (i, yi) and the point (i + 1, yi + 1). For any even i (2 ≤ i ≤ 2n) the following condition holds: yi - 1 < yiand yi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
Bolek fancied a little mischief. He chose exactly k mountain peaks, rubbed out the segments that went through those peaks and increased each peak's height by one (that is, he increased the y coordinate of the corresponding points). Then he painted the missing segments to get a new picture of mountain peaks. Let us denote the points through which the new polyline passes on Bolek's new picture as (1, r1), (2, r2), ..., (2n + 1, r2n + 1).
Given Bolek's final picture, restore the initial one.
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100). The next line contains 2n + 1 space-separated integersr1, r2, ..., r2n + 1 (0 ≤ ri ≤ 100) — the y coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the given picture after performing the described actions on some picture of mountain peaks.
Print 2n + 1 integers y1, y2, ..., y2n + 1 — the y coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them.
3 20 5 3 5 1 5 2
0 5 3 4 1 4 2
1 10 2 0
0 1 0
代码:
#include <iostream>
using namespace std;
const int N = 1000;
int main()
{
int n,k;
int a[N];
cin>>n>>k;
for(int i=0;i<=2*n;i++)
{
cin>>a[i];
}
for(int i=0;i<=2*n;i++)
{
if(k && i%2==1 && a[i]-a[i-1]>1 && a[i]-a[i+1]>1)
{
a[i]--;
k--;
}
cout<<a[i]<<' ';
}
return 0;
}
- Codeforces---Mountain Scenery
- Codeforces Round #134 (Div. 2)A. Mountain Scenery
- Codeforces Round #134 (Div. 2)A. Mountain Scenery(简单)
- Codeforces Round #134 (Div. 2) A. Mountain Scenery
- A. Mountain Scenery
- Rural Scenery
- Blender 3D Architecture, Buildings, and Scenery
- I want to see more scenery.
- COLD MOUNTAIN
- Mountain climbing
- Brokeback Mountain
- Thunder Mountain
- Mountain Number
- Thinking in Brokeback Mountain
- about "Brokeback Mountain"
- 回到Mountain View
- uva 10803 - Thunder Mountain
- Mountain Huangshan Scenic Spot1
- 安装bcb6出现的问题
- Android APK反编译得到Java源代码和资源文件
- cascade与inverse的作用
- win7专业版安装SQL2008 问题
- Linux系统获取sata硬盘序列号
- Codeforces---Mountain Scenery
- XSS 注入
- e.Item.ItemType、ListItemType.Item 的解释
- 微内核和单内核
- .net 网站 播放flv格式视频
- Spring 实现AOP功能
- android AsyncTask介绍
- dataview
- 关于线程堆栈大小的注意事项