zoukankan      html  css  js  c++  java
  • 水题——415A. Mashmokh and Lights

    A. Mashmokh and Lights
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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 m distinct buttonsb1, 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.

    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 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

    Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.

    Examples
    input
    5 4
    4 3 1 2
    output
    1 1 3 4 4 
    input
    5 5
    5 4 3 2 1
    output
    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.

    题意:有n盏灯和开关1,,2,3...第n个开关可以把第n个灯及其后面的灯关闭,操作了m次,每次按下一个开关,保证所有的灯最后都被关闭了,要求输出每个灯是被哪个开关关闭的。

     1 /*A*/
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int n,m;
     9     int a[100+10];
    10     int ans[100+10];
    11     int vis[100+10];
    12     while(scanf("%d%d",&n,&m)!=EOF)
    13     {
    14         for(int i=0;i<m;i++)
    15             scanf("%d",&a[i]);
    16         memset(ans,0,sizeof(ans));
    17         memset(vis,0,sizeof(vis));
    18         for(int i=0;i<m;i++)
    19         {
    20             if(vis[a[i]]==0)
    21             {
    22                 for(int j=a[i];j<=n;j++)
    23                 {
    24                     if(vis[ans[j]]==0)
    25                     {
    26                         ans[j]=a[i];
    27                         vis[j]=1;
    28                     }
    29                 }
    30             }
    31         }
    32         printf("%d ",ans[1]);
    33         for(int i=2;i<=n;i++)
    34             printf("%d ",ans[i]);
    35         printf("
    ");
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    openstack nova创建虚拟机过程(DEBUG)从接收到cli RESTFul请求到给scheduler发送rpc消息
    openstack源码阅读基础:openstack中Nova组件RESTful请求的具体处理函数确定
    博客园第一搏——Html5 JumpStart学习笔记1:Semantic Structure
    我的CSDN博客http://blog.csdn.net/kuangjian007,欢迎骚扰!
    django第一课:基本介绍
    pku 1142 Smith Number
    使用Eclipse开发X3D
    javascript树形控件第二版
    三种方式获得int的size
    细节决定成败
  • 原文地址:https://www.cnblogs.com/yepiaoling/p/5313245.html
Copyright © 2011-2022 走看看