CF253A Boys and Girls 题解
Content
有 \(n\) 个男生、\(m\) 个女生坐在一排,请求出这样一种方案,使得相邻两个座位之间的人的性别不同的次数最多。
数据范围:\(1\leqslant n,m\leqslant 100\)。
Solution
这题不难,就是先把能男女组合的尽量组合了,然后剩余有多的直接丢在后面不管(或者也可以先把多的求出来然后丢在前面,但是不如本方法方便,读者可以亲自尝试),但是有坑点:
- 这题目要开文件输入输出!所以千万不要忘了 \(\texttt{freopen}\)。
- 如果是女生多,则两两组合时先让女生在前,男生在后,这样才能尽可能地满足题目要求。如果是男生多,则两两组合时先让男生在前,女生在后。
跳过这些坑点,胜利其实就在眼前了。
Code
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n, m, minx;
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d%d", &n, &m);
minx = min(n, m);
for(int i = 1; i <= minx; ++i)
printf(minx == n ? "GB" : "BG");
n -= minx, m -= minx;
if(n) for(int i = 1; i <= n; ++i) printf("B");
else for(int i = 1; i <= m; ++i) printf("G");
return 0;
}
CF253A Boys and Girls 题解的更多相关文章
- PAT 甲级 1036 Boys vs Girls (25 分)(简单题)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT1036:Boys vs Girls
1036. Boys vs Girls (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue This ti ...
- 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 1036 Boys vs Girls[简单]
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...
- PAT 1036 Boys vs Girls (25 分)
1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade ...
- PAT甲级——1036 Boys vs Girls
1036 Boys vs Girls This time you are asked to tell the difference between the lowest grade of all th ...
- 1036 Boys vs Girls (25分)(水)
1036 Boys vs Girls (25分) This time you are asked to tell the difference between the lowest grade o ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题
题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...
随机推荐
- Ubuntu 软件安装
apt 使用apt安装,需要sudo 一些命令: sudo apt-get install git deb deb软件安装方法: sudo dpkg -I xxxx.deb 我们在Windows下安装 ...
- 【Spring】(1)-- 概述
Spring框架 -- 概述 2019-07-07 22:40:42 by冲冲 1. Spring的概念 ① Spring框架的关键词:开源框架.轻量级框架.JavaEE/J2EE开发框架.企业级 ...
- 设计模式学习-使用go实现访问者模式
访问者模式 定义 优点 缺点 适用范围 代码实现 什么是 Double Dispatch 参考 访问者模式 定义 访问者模式(Visitor):表示一个作用于某对象结构中的各元素的操作.它使你可以在不 ...
- [省选联考 2021 A 卷] 矩阵游戏
很巧妙的一个构造. 我是没有想到的. 自己的思维能力可能还是不足. 考虑先满足\(b\)对\(a\)的限制,把\(a\)的第一行和第一列设\(0\),推出这个\(a\). 接下来考虑对这个\(a\), ...
- 间断有限元h自适应处理方法
细分单元 function Hrefine2D(refineflag) 根据refineflag变量细分单元,其中refineflag变量大小为 [Kx1],需要细分单元标记为1,不需要单元为0. 根 ...
- Linux 中的五种 IO 模型
Linux 中的五种 IO 模型 在正式开始讲Linux IO模型前,比如:同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的上下文下给出的答案是不同的.所以先限定一 ...
- SpringCloud微服务实战——搭建企业级开发框架(三十):整合EasyExcel实现数据表格导入导出功能
批量上传数据导入.数据统计分析导出,已经基本是系统必不可缺的一项功能,这里从性能和易用性方面考虑,集成EasyExcel.EasyExcel是一个基于Java的简单.省内存的读写Excel的开源项 ...
- Shell 统计文件的行数
目录 统计文件的行数 题目 题解-awk 题解-wc 题解sed 统计文件的行数 题目 写一个 bash脚本以输出一个文本文件 nowcoder.txt中的行数 示例: 假设 nowcoder.txt ...
- 学习java 7.10
学习内容: List 集合:有序集合,用户可以精确控制列表中每个元素的插入位置 List 集合特点:有序:存储和取出的元素顺序一致 可重复:存储的元素可以重复 增强for循环:简化数组和 Collec ...
- 前端必须知道的 Nginx 知识
Nginx一直跟我们息息相关,它既可以作为Web 服务器,也可以作为负载均衡服务器,具备高性能.高并发连接等. 1.负载均衡 当一个应用单位时间内访问量激增,服务器的带宽及性能受到影响, 影响大到自身 ...