Codeforces Round #134 (Div. 2)A. Mountain Scenery(简单)
2012-08-20 10:34
537 查看
A. Mountain Scenery
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 + 1points
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 andyi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
The figure to the
left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k =
2.
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.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100).
The next line contains2n + 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.
Output
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.
Sample test(s)
input
output
input
output
主要注意:following condition holds: yi - 1 < yi andyi > yi + 1.即可。答案不唯一。
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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 + 1points
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 andyi > yi + 1.
We shall call a vertex of a polyline with an even x coordinate a mountain peak.
The figure to the
left shows the initial picture, the figure to the right shows what the picture looks like after Bolek's actions. The affected peaks are marked red, k =
2.
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.
Input
The first line contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 100).
The next line contains2n + 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.
Output
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.
Sample test(s)
input
3 2 0 5 3 5 1 5 2
output
0 5 3 4 1 4 2
input
1 1 0 2 0
output
0 1 0
主要注意:following condition holds: yi - 1 < yi andyi > yi + 1.即可。答案不唯一。
#include <iostream> using namespace std; int a[205]; int main() { int n, k; while(cin >> n >>k) { for(int i = 0; i < 2 * n + 1; i++) cin >> a[i]; for(int i = 1; k; i += 2) if(a[i] - 1 > a[i - 1] && a[i] - 1 > a[i + 1]) { a[i]--; k--; } for(int i = 0; i < 2 * n; i++) cout << a[i] << " "; cout << a[2 * n] << endl; } return 0; }
相关文章推荐
- Codeforces Round #134 (Div. 2)A. Mountain Scenery(简单)
- Codeforces Round #130 (Div. 2)A Dubstep(简单字符串处理)
- 并查集Codeforces Round #134 (Div. 1), problem: (A) Ice Skating
- Codeforces Round #134 (Div. 2)A. Mountain Scenery
- Codeforces Round #134 (Div. 2) A. Mountain Scenery
- Codeforces Round #379 (Div. 2) B. Anton and Digits(简单贪心)
- Codeforces Round #402 (Div. 2) D(简单)(二分)
- Codeforces Round #134 (Div. 2)B. Airport
- 【Codeforces Round 333 (Div 2)A 】【水题 简单进制模拟】Two Bases 不同进制数比大小
- Codeforces Round #327 (Div. 2) (A. Wizards' Duel 简单数学)
- Codeforces Round #343 (Div. 2) C. Famil Door and Brackets(简单dp)
- Codeforces Round #220 (Div. 2) A. Inna and Pink Pony 这个题目不简单的
- Codeforces Round #134 (Div. 2) B. Airport
- 【Codeforces Round 375 (Div 2) D】【简单dfs】Lakes in Berland
- Codeforces Round #302 (Div. 2) C 简单dp
- 【Codeforces Round 364 (Div 2)B】【简单讨论】Cells Not Under Attack 行列炮台覆盖不被攻击格子数
- Codeforces Round #134 (Div. 2)C. Ice Skating
- Codeforces Round #134 (Div. 2) A_B_C_D题
- Codeforces Round #387 (Div. 2)A. Display Size(简单数学)
- Codeforces Round #272 (Div. 2) B Dreamoon and WiFi(简单DP)