您的位置:首页 > 其它

Educational Codeforces Round 11B. Seating On Bus 模拟

2016-04-09 16:08 381 查看

地址:http://codeforces.com/contest/660/problem/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.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector>

#define PI acos((double)-1)
#define E exp(double(1))
using namespace std;
int seat[110][5];
int main (void)
{
int n,m;
cin>>n>>m;
memset(seat,0,sizeof(seat));
for(int i=1;i<=m;i++)
if(i<=2*n)
{
if(i%2 == 1)
seat[(i+1)/2][2] = i;
else
seat[i/2][4] = i;
}
else
{
int t = i-2*n;
if(t%2 == 1)
seat[(t+1)/2][1]=i;
else
seat[t/2][3] = i;
}
for(int i=1,k=1;k<=m && i<=n;i++)
for(int j = 1;j<=4;j++)
if(seat[i][j])
{
if(k == m)
printf("%d\n",seat[i][j]);
else
printf("%d ",seat[i][j]);
k++;
}

return 0;
}
View Code

 

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: