CodeForces 415A Mashmokh and Lights
来源:互联网 发布:联合培养博士 知乎 编辑:程序博客网 时间:2024/05/16 14:59
链接:http://codeforces.com/problemset/problem/415/A
Mashmokh and Lights
Mashmokh works in a factory. At the end of each day he must turn off all of the lights.
The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from1 to n as well. If Mashmokh pushes button with indexi, then each light with index not less thani that is still turned on turns off.
Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushedm distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of buttonbi is actuallybi, noti.
Please, help Mashmokh, print these indices.
Input
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line containsm distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n).
It is guaranteed that all lights will be turned off after pushing all buttons.
Output
Output n space-separated integers where thei-th number is index of the button that turns thei-th light off.
Sample test(s)
5 44 3 1 2
1 1 3 4 4
5 55 4 3 2 1
1 2 3 4 5
Note
In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.
直接模拟,附上AC代码:
#include <iostream>#include <cstdio>#include <string>#include <cmath>#include <iomanip>#include <ctime>#include <climits>#include <cstdlib>#include <cstring>#include <algorithm>#include <queue>#include <vector>#include <set>#include <map>//#pragma comment(linker, "/STACK:102400000, 102400000")using namespace std;typedef unsigned int li;typedef long long ll;typedef unsigned long long ull;typedef long double ld;const double pi = acos(-1.0);const double e = exp(1.0);const double eps = 1e-8;const short maxn = 105;short n, m, button;short buttons[maxn];int main(){ios::sync_with_stdio(false);while (~scanf("%hd%hd", &n, &m)){memset(buttons, 0, sizeof(buttons));while (m--){scanf("%hd", &button);for (short i=button; i<=n; i++)if (buttons[i] == 0)buttons[i] = button;}for (short i=1; i<n; i++)printf("%hd ", buttons[i]);printf("%hd\n", buttons[n]);}return 0;}
- CodeForces 415A Mashmokh and Lights
- 415A Mashmokh and Lights
- Codeforces 415A Mashmokh and Lights(水题)
- A. Mashmokh and Lights
- code forces 415A Mashmokh and Lights
- Codeforces Round #240 (Div. 2) A. Mashmokh and Lights
- cf,A. Mashmokh and Lights
- cf——A. Mashmokh and Lights
- Mashmokh and Lights
- Codeforces 414A Mashmokh and Numbers(构造)
- Codeforces 414A Mashmokh and ACM(dp)
- CodeForces 414A Mashmokh and Numbers
- CodeForces 414A Mashmokh and Numbers
- codeforces 415B Mashmokh and Tokens
- CodeForces 415B Mashmokh and Tokens
- codeforces 415B Mashmokh and Tokens
- Codeforces 415D Mashmokh and ACM DP
- codeforces Mashmokh and Tokens
- 非排序寻找从小到大第3400个数
- pat1007Maximum Subsequence Sum (25)
- 链表(Java)
- UIstoryboard
- 工作常用第三方框架
- CodeForces 415A Mashmokh and Lights
- HDU 2104 GCD
- 谓词的补充——使用谓词还可以进行正则表达式的验证
- 进程间的通信(浅谈)
- ocp-37
- 大数字相加
- MyISAM vs InnoDB 分析之一
- HashTable的实现原理分析
- ocp-38