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 ...
随机推荐
- C++调用GDAL库读取并输出tif文件,并计算斑块面积输出景观指数:CSD
部分源码选自GDAL库的官方网址:www.gdal.org,其余的代码为笔者自己编写. // readfile.cpp : 定义控制台应用程序的入口点. // /* part of the codes ...
- codevs 3186 队列练习2
3186 队列练习 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description (此题与队列练习1相比改了2处:1加 ...
- Linux读写锁的使用
读写锁是用来解决读者写者问题的,读操作可以共享,写操作是排它的,读可以有多个在读,写只有唯一个在写,写的时候不允许读. 具有强读者同步和强写者同步两种形式: 强读者同步:当写者没有进行写操作时,读者就 ...
- 【OSG细节实现】节点围绕位于axisPos平行于axis的轴进行旋转
//绕着与axis平行的任意轴旋转 void rotate(const std::string& name, float angle, osg::Vec3 axisPos, osg::Vec3 ...
- Windows Phone 7 ListBox 列表项渐显加载动画学习笔记
在wp7程序中,当程序功能越来越复杂时,性能问题是我们不得不考虑的一个问题.在聊天列表中,如果聊天项过多,而且项目UI组件足够复杂时, 我们不得不想尽办法让UI尽快加载.所以有一种可行的方案,就是像Q ...
- FPGA的图像处理技术,你知道多少?
最近一段时间一直在研究基于FPGA的图像处理,乘着EEPW这个机会和大家交流一下,自己也顺便总结一下.主要是为了大家对用FPGA做图像处理有个感性的认识,如果真要研究的话就得更加深入学习了.本人水平有 ...
- PHP 如何判断当前用户已在别处登录
出处:http://bbs.lampbrother.net/read-htm-tid-121909-ds-1.html#tpc 主要思路:1.登录时,将用户的SessionID记录下来2.验证登录时, ...
- online learning
转自http://blog.csdn.net/sjkldjflakj/article/details/51886277 不同于以往的批量学习,即给了许多的已标记好的资料来学习出一个假设函数,onlin ...
- Python开发【第一篇】Python基础之装饰器
写代码要遵循开发封闭原则,虽然在这个原则是用的面向对象开发,但是也适用于函数式编程,简单来说,它规定已经实现的功能代码不允许被修改,但可以被扩展,即: 封闭:已实现的功能代码块开放:对扩展开发 #s2 ...
- JS对Json对象Distinct
Json对象去重 今日有一个需求如下: 从数据库中取出数据源转化成json字符串绑定到隐藏域中,取出的json字符串如下: string data="[{"CompanyName& ...