Codeforces Round #240 (Div. 2)->A. Mashmokh and Lights
1 second
256 megabytes
standard input
standard output
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 from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i 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 pushed mdistinct 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 button bi is actually bi, not i.
Please, help Mashmokh, print these indices.
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 contains m 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 n space-separated integers where the i-th number is index of the button that turns the i-th light off.
5 4
4 3 1 2
1 1 3 4 4
5 5
5 4 3 2 1
1 2 3 4 5
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.
题意:按了某个按键a[i],>=a[i]的数字的灯都会被关掉(如果那只灯已经关了就不记录,也就是每个关的灯输出的都是让它第一次关的数字,做个标记就行了),输出第i只灯是按哪只灯时关掉的。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int a[],b[]= {};
for(int i=; i<m; i++)
{
cin>>a[i];
for(int j=a[i]-; j<n; j++)
{
if(b[j]==)
b[j]=a[i];
}
}
for(int i=; i<n; i++)
{
printf("%d%c",b[i],i==n-?'\n':' ');
}
return ;
}
Codeforces Round #240 (Div. 2)->A. Mashmokh and Lights的更多相关文章
- Codeforces Round #240 (Div. 1) B. Mashmokh and ACM DP
B. Mashmokh and ACM ...
- Codeforces Round #240 (Div. 2) C Mashmokh and Numbers
, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge ...
- Codeforces Round #240 (Div. 2)(A -- D)
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...
- Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp)
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university ...
- Codeforces Round #240 (Div. 2) B 好题
B. Mashmokh and Tokens time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #240 (Div. 2) D
, b2, ..., bl (1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n) is called good if each number divides (without a remainde ...
- Codeforces Round #240 (Div. 2) 题解
A: 1分钟题,往后扫一遍 int a[MAXN]; int vis[MAXN]; int main(){ int n,m; cin>>n>>m; MEM(vis,); ; i ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- 20150320--安全性,Membership类
安全性--验证与授权,成员资格与角色. 一.成员资格与角色, 第一步:注册数据库,在VS中运行dos命令窗口中,输入:aspnet_regsql,建立数据库表. 如何启动VS的dos命令窗口,在 . ...
- Base Pattern基本模式_Gateway入口
•Gateway入口 ◦一个封装了对外部系统或资源访问的对象. ◾OO系统中,也需要访问一些不是对象的事物,DB表,XML,事务. ◾这些外部资源的API很复杂. ◾入口类对象将简单的方法调用转换成相 ...
- webSphere集群部署主要步骤
1.系统管理-节点,添加本机节点和另外一台机器的节点2.建立集群服务cluster,添加成员节点3.将应用部署到集群服务cluster4.将数据库源分别建立到节点作用域5.后续步骤参照安装手册 注意事 ...
- Linux开机启动程序详解[转]
Linux开机启动程序详解 我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤 ...
- Linux系统目录分析
Linux系统目录分析 /bin :系统指令目录(如ls.cp.mv等指令) /dev :系统设备目录 /home :系统用户的家,每一个系统用户都在此目录下有一个自己的家,每次登录时,系统都会自动登 ...
- C++ 构造函数讲解
构造函数是C++.Java等面向对象编程语言不可绕过的话题,构造函数的作用就是初始化所创建对象的数据成员.不过与Java相比C++的构造函数显得更为复杂.因此,现在便来讲解一下C++的构造函数,以此进 ...
- 安装php-posix
1.安装php-posix 1 yum -y install php-process 2.验证是否安装上了 1 php -m|grep posix 1 posix
- Objective-C中字典的使用方法总结
在Objective-C中提供了两个类来实现字典,即NSDictionary和NSMutableDictionary.其中,NSMutableDictionary是NSDictionary的子类,它继 ...
- Android app version code and name
android:versionCode和android:versionName 区别 Android的版本可以在androidmainfest.xml中定义, 主要有android:version ...
- 例题6-3 Matrix Chain Multiplication ,Uva 442
这个题思路没有任何问题,但还是做了近三个小时,其中2个多小时调试 得到的经验有以下几点: 一定学会调试,掌握输出中间量的技巧,加强gdb调试的学习 有时候代码不对,得到的结果却是对的(之后总结以下常见 ...