本文主要是介绍CF Bayan 2015 Contest Warm Up A.(模拟+预处理),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
time limit per test
2 seconds
memory limit per test
256 megabytes
standard input
output
standard output
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.
The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one.
In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.
Input
The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.
Output
Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.
Sample test(s)
Input
9
Output
+------------------------+ |O.O.O.#.#.#.#.#.#.#.#.|D|) |O.O.O.#.#.#.#.#.#.#.#.|.| |O.......................| |O.O.#.#.#.#.#.#.#.#.#.|.|) +------------------------+
Input
20
Output
+------------------------+ |O.O.O.O.O.O.O.#.#.#.#.|D|) |O.O.O.O.O.O.#.#.#.#.#.|.| |O.......................| |O.O.O.O.O.O.#.#.#.#.#.|.|) +------------------------+
解题思路:
先打表再模拟。题意是让你模拟输出k个人的公交车位置图。O代表这个座位有人坐,#代表这个座位没人做,D代表驾驶员的位置,其他的格式如样例所示。
首先通过预处理把格式打出来。要特别注意下第三行的情况(不算加号那行),那行最多只能有一个O,作特殊处理。最后只要按列优先往里面填人就行了。
完整代码:
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;char g[4][26];void init()
{for(int i = 0 ; i < 4 ; i ++){for(int j = 0 ; j < 26 ; j ++){if(j == 0)g[i][j] = '|';else if(j == 23){if(i != 2)g[i][j] = '|';elseg[i][j] = '.';}else if(j == 25)g[i][j] = '|';else if(j == 24 && i == 0)g[i][j] = 'D';else if(i == 2 && j > 1 && j <= 22)g[i][j] = '.';else if(i == 2 && j == 1)g[i][j] = '#';else{if(j % 2 == 0)g[i][j] = '.';elseg[i][j] = '#';}}}
/*for(int i = 0 ; i < 4 ; i ++){for(int j = 0 ; j < 26 ; j ++){cout << g[i][j] ;}cout << endl;}
*/
}int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifint k;while(~scanf("%d",&k)){init();for(int j = 1 ; j < 22 ; j ++){for(int i = 0 ; i < 4 ; i ++){if(i == 2 && j != 1)continue;if(j % 2 == 1){if(k){g[i][j] = 'O';k--;}}}}printf("+------------------------+\n");for(int i = 0 ; i < 4 ; i ++){for(int j = 0 ; j < 26 ; j ++){printf("%c",g[i][j]);}if(i == 0)printf(")\n");else if(i == 3)printf(")\n");elseprintf("\n");}printf("+------------------------+\n");}
}
这篇关于CF Bayan 2015 Contest Warm Up A.(模拟+预处理)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!