CF475A Bayan Bus 题解
Update
- \(\texttt{2020.10.6}\) 修改了一些笔误。
Content
模拟一个核载 \(34\) 人的巴士上有 \(k\) 个人时的巴士的状态。
每个人都会优先选择有空位的最后一排最左侧一个空位入座。
数据范围:\(0\leqslant k\leqslant 34\)。
Solution
有 \(6\) 行,所以按 \(6\) 行来分类讨论。
Part 1 第一行
第一行只需要输出一串字符串就行了,不需要多讲。
由于第六行输出的东西和第一行一模一样,故之后不做详细讲解。
Part 2 第二行
第二行开始一直到第五行都需要考虑到车上的人的情况。我们先来看这一行。
首先得要考虑最后一排的情况(因为最后一排有 \(4\) 个人)。
- 如果 \(k=0\),那么最后一排上的这一列不坐人。
- 否则,这里肯定会坐人。
然后,还有坐在这一列的人数 \(p_2=\left\lceil\dfrac{\max\{0,k-4\}}{3}\right\rceil\),没坐在这一列的人数则是 \(10-p_2\)。这个可以自己去推算。
Part 3 第三行
首先还是考虑最后一排的情况。
- 如果 \(k<2\),那么这里不坐人。
- 否则,这里肯定坐人。
然后,还有坐在这一列的人数 \(p_3=\left\lceil\dfrac{\max\{0,k-5\}}{3}\right\rceil\),没坐在这一列的人数则是 \(10-p_3\)。
由于第五行与第二、三行的情况类似,故之后不做详细讲解。
Part 4 第四行
首先还是考虑最后一排的情况。
- 如果 \(k<3\),那么这里不坐人。
- 否则,这里肯定坐人。
然后这里就是过道了,直接输出 .(经检验总共有 \(22\) 个)。
其他的不做多讲。
注意,除了我讲的东西要输出外,每一行后面可能还会有一些多余的东西,它们也要输出。
Code
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
int k;
scanf("%d", &k);
printf("+------------------------+\n|");
if(!k) printf("#.");
else printf("O.");
for(int i = 1; i <= (int)ceil(max(0, k - 4) / 3.0); ++i) printf("O.");
for(int i = 1; i <= 10 - (int)ceil(max(0, k - 4) / 3.0); ++i) printf("#.");
printf("|D|)\n|");
if(k < 2) printf("#.");
else printf("O.");
for(int i = 1; i <= (int)ceil(max(0, k - 5) / 3.0); ++i) printf("O.");
for(int i = 1; i <= 10 - (int)ceil(max(0, k - 5) / 3.0); ++i) printf("#.");
printf("|.|\n|");
if(k < 3) printf("#.");
else printf("O.");
for(int i = 1; i <= 22; ++i) printf(".");
printf("|\n|");
if(k < 4) printf("#.");
else printf("O.");
for(int i = 1; i <= (int)ceil(max(0, k - 6) / 3.0); ++i) printf("O.");
for(int i = 1; i <= 10 - (int)ceil(max(0, k - 6) / 3.0); ++i) printf("#.");
printf("|.|)\n+------------------------+");
}
CF475A Bayan Bus 题解的更多相关文章
- cf475A Bayan Bus
A. Bayan Bus time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Bzoj 1537: [POI2005]Aut- The Bus 题解 [由暴力到正解]
1537: [POI2005]Aut- The Bus Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 387 Solved: 264[Submit][S ...
- codeforces A. Bayan Bus(简单模拟)
#include <queue> #include <string> #include <cstdio> #include <cstring> #inc ...
- codeforces 475A.Bayan Bus 解题报告
题目链接:http://codeforces.com/problemset/problem/475/A 题目意思:输入一个整数 k(0 ≤ k ≤ 34),表示participants的人数,需要在一 ...
- codeforces CF475 ABC 题解
Bayan 2015 Contest Warm Up http://codeforces.com/contest/475 A - Bayan Bus B - Strongly Connected Ci ...
- 洛谷 题解 CF711A 【Bus to Udayland】
先用一个字符数组存每行的座位情况(字符变量也可以) 接下来用另一个数组存最后的座位情况 好了,看代码 #include<iostream> using namespace std; boo ...
- CF792A New Bus Route 题解
Content 给定一个长度为 \(n\) 的数列 \(a_1,a_2,a_3,...,a_n\),求这个序列当中差的绝对值最小的数对并求出这样的数对的个数. 数据范围:\(2\leqslant n\ ...
- [BZOJ 2004] [Hnoi2010] Bus 公交线路 【状压DP + 矩阵乘法】
题目链接: BZOJ - 2004 题目分析 看到题目完全不会..于是立即看神犇们的题解. 由于 p<=10 ,所以想到是使用状压.将每个连续的 p 个位置压缩成一个 p 位 2 进制数,其中共 ...
- BZOJ1537: [POI2005]Aut- The Bus
1537: [POI2005]Aut- The Bus Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 158 Solved: 100[Submit][S ...
随机推荐
- python 配置pip镜像源
在本地用户下新建pip文件夹,新建pip.ini [global] index-url = http://mirrors.aliyun.com/pypi/simple/ [install] trust ...
- 洛谷 P5902 [IOI2009]salesman(dp)
题面传送门 题意: 有 \(n\) 个展销会,每个展销会给出它的时间 \(t_i\),举办展销会的位置 \(l_i\),和参加这个展销会你能得到的收益 \(m_i\). 你现在在位置 \(s\),你可 ...
- Codeforces 685C - Optimal Point(分类讨论+乱搞)
Codeforces 题面传送门 & 洛谷题面传送门 分类讨论神题. 首先看到最大值最小,一眼二分答案,于是问题转化为判定性问题,即是否 \(\exists x_0,y_0,z_0\) 满足 ...
- C++ and OO Num. Comp. Sci. Eng. - Part 1.
本文参考自 <C++ and Object-Oriented Numeric Computing for Scientists and Engineers>. 序言 书中主要讨论的问题是面 ...
- 66-Reorder List
Reorder List My Submissions QuestionEditorial Solution Total Accepted: 64392 Total Submissions: 2818 ...
- nginx二级域名指向不同文件项目配置
需要使用泛域名解析, 并且加上空的判断,以保证没有二级域名的也可以访问 核心配置 server_name ~^(?<subdomain>.+)\.caipudq\.cn$;if ( $su ...
- 14-Reverse Integer
思路: 先判定符号,整型范围[-2^32,2^32] 取余除10操作,依次进行,越界返回0 Reverse digits of an integer. Example1: x = 123, retur ...
- Java日期时间操作基础——包含JDK1.8时间操作新特性
JDK1.7日期时间操作 示例小结 public class DateTest { public static final String FORMAT_DATE = "yyyy-MM-dd& ...
- c#页面查询、数据显示
page : <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Queryx ...
- c#Gridview添加颜色
e.Row.Cells[1].ForeColor = System.Drawing.Color.Blue;