A. Mountain Scenery
来源:互联网 发布:程序员是干嘛的 编辑:程序博客网 时间:2024/05/22 15:41
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 < yi and 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 integers r1, 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
解题说明:就是找比旁边两个低谷高度高1以上的山峰,高度减1输出就可以了。只把先遇到的 k 个符合条件的山峰高度-1输出,后面的不管。注意山峰点肯定是在奇数的位置,偶数的部分都是山谷,需要加一个判断。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;int main(){int a[300],n,k,i;scanf("%d %d",&n,&k);n=2*n+1;for(i=0;i<n;i++){scanf("%d",&a[i]);}for(i=0;i<n;i++){if(i%2==1){if(a[i]>a[i-1]+1&&a[i]>a[i+1]+1&&k>0){a[i]--;k--;}}printf("%d ",a[i]);}printf("\n");}
- A. 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
- Codeforces---Mountain Scenery
- Rural Scenery
- Disaster on a mountain 山中救援
- 118. Don't make a mountain out of a molehill. 不要小题大作
- Blender 3D Architecture, Buildings, and Scenery
- I want to see more scenery.
- poj 2673 Kicc Wants to Move a Mountain! 模拟水题
- COLD MOUNTAIN
- Mountain climbing
- Brokeback Mountain
- Thunder Mountain
- Mountain Number
- Thinking in Brokeback Mountain
- about "Brokeback Mountain"
- 查看debian版本
- sql操作类【java】
- MFC中各指针的获取
- debian7 安装Rhythmbox歌词插件
- LayoutInflater作用及使用
- A. Mountain Scenery
- gnuplot 使用方法
- python乱码问题
- mysql判断某一张表是否存在
- 解决JS弹出新窗口被浏览器阻止的解决方案
- HDU-1059-Dividing-多重背包
- python datetime,time转换操作
- 【windows7没有声音解决思路】
- WaitForSingleObject 和 WaitForMultipleObjects函数