zoukankan      html  css  js  c++  java
  • 模拟——Educational Codeforces Round 11——B

    B. Seating On Bus
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Consider 2n rows of the seats in a bus. n rows of the seats on the left and n rows of the seats on the right. Each row can be filled by two people. So the total capacity of the bus is 4n.

    Consider that m (m ≤ 4n) people occupy the seats in the bus. The passengers entering the bus are numbered from 1 to m (in the order of their entering the bus). The pattern of the seat occupation is as below:

    1-st row left window seat, 1-st row right window seat, 2-nd row left window seat, 2-nd row right window seat, ... , n-th row left window seat,n-th row right window seat.

    After occupying all the window seats (for m > 2n) the non-window seats are occupied:

    1-st row left non-window seat, 1-st row right non-window seat, ... , n-th row left non-window seat, n-th row right non-window seat.

    All the passengers go to a single final destination. In the final destination, the passengers get off in the given order.

    1-st row left non-window seat, 1-st row left window seat, 1-st row right non-window seat, 1-st row right window seat, ... , n-th row left non-window seat, n-th row left window seat, n-th row right non-window seat, n-th row right window seat.

    The seating for n = 9 and m = 36.

    You are given the values n and m. Output m numbers from 1 to m, the order in which the passengers will get off the bus.

    Input

    The only line contains two integers, n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 4n) — the number of pairs of rows and the number of passengers.

    Output

    Print m distinct integers from 1 to m — the order in which the passengers will get off the bus.

    Examples
    input
    2 7
    output
    5 1 6 2 7 3 4
    input
    9 36
    output
    19 1 20 2 21 3 22 4 23 5 24 6 25 7 26 8 27 9 28 10 29 11 30 12 31 13 32 14 33 15 34 16 35 17 36 18

    题意:有2n排座位,n排在左边,n排在右边。有m个人(编号为1-m)依次上车,优先坐左边靠窗的座位,再是右边靠窗的座位,然后是左边不靠窗,最后是右边不靠窗。要输出下车时人的循序编号。
    下车时左边第一排不靠窗先下,然后是靠窗,再是右边第一排不靠窗下,然后靠窗,每一排依次下车直到所有人下车。
    题解:模拟即可。
     1 /*B*/
     2 #include<cstdio>
     3 #include<cstring>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int n,m;
     9     int seat[5][110];
    10     while(scanf("%d%d",&n,&m)!=EOF)
    11     {
    12         memset(seat,0,sizeof(seat));
    13         seat[1][1]=1;seat[4][1]=2;
    14         for(int i=2;i<=n;i++)
    15         {
    16             seat[1][i]=seat[1][i-1]+2;
    17             seat[4][i]=seat[4][i-1]+2;
    18         }
    19         seat[2][1]=seat[4][n]+1;seat[3][1]=seat[2][1]+1;
    20         for(int i=2;i<=n;i++)
    21         {
    22             seat[2][i]=seat[2][i-1]+2;
    23             seat[3][i]=seat[3][i-1]+2;
    24         }
    25         for(int i=0;i<=4;i++)
    26             for(int j=0;j<=n;j++)
    27                 if(seat[i][j]>m)
    28                     seat[i][j]=0;
    29         int s=0;
    30         for(int i=1;i<=n;i++)
    31         {
    32             if(seat[2][i])
    33             {
    34                 printf("%d ",seat[2][i]);
    35                 s++;
    36             }
    37             if(s==m)    break;
    38             if(seat[1][i])
    39             {
    40                 printf("%d ",seat[1][i]);
    41                 s++;
    42             }
    43             if(s==m)    break;
    44             if(seat[3][i])
    45             {
    46                 printf("%d ",seat[3][i]);
    47                 s++;
    48             }
    49             if(s==m)    break;
    50             if(seat[4][i])
    51             {
    52                 printf("%d ",seat[4][i]);
    53                 s++;
    54             }
    55             if(s==m)    break;
    56         }
    57         printf("
    ");
    58     }
    59     return 0;
    60 }
    View Code
    
    
  • 相关阅读:
    阿里云(一)云存储OSS的命令行osscmd的安装和使用
    Zephir入门教程一
    【转载】视频CDN技术原理与流程说明
    博客园页面css样式
    Linux使用imagemagick的convert命令压缩图片、节省服务器空间
    WebSockets Tutorial(教程一)WebSockets简介
    ngx_lua_API 指令详解(四)ngx.exec指令
    Git与GitHub学习笔记(二)提交的一些笔记
    这些万能的文献检索工具,你用了几个?
    干货||科研收藏夹必备35个学术网址
  • 原文地址:https://www.cnblogs.com/yepiaoling/p/5380125.html
Copyright © 2011-2022 走看看