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一遍找最大最小值,水题 # ...
随机推荐
- 如何用LOTO示波器TDR方法测试电线长度?
TDR也就是时域反射(Time-domain reflectometer),它可以通过观察导线中反射回来的电信号波形对导线长度进行测量,或者对传输导线的阻抗特性进行分析评估. 我们经常会碰到的TDR的 ...
- layui页面操作,点击一个添加页面,跳转有确定,然后点击确定后将选择的几个数据返回前一个页面获取值,然后ajax请求后台
custUserIndex.html [添加页面代码] <!DOCTYPE html> <html> <head> <meta charset="u ...
- 面试官问我HTTP,我真的是
面试官:今天要不来聊聊HTTP吧? 候选者:嗯,HTTP「协议」是客户端和服务器「交互」的一种通迅的格式 候选者:所谓的「协议」实际上就是双方约定好的「格式」,让双方都能看得懂的东西而已 候选者:所谓 ...
- CF1175G
叉姐牛逼. \(f_{k,i} = \min_{0\leq j <i}{f_{k - 1,j} + RMQ(j + 1,i) * (i - j)}\) 我们考虑在序列上分治一波. 按照\(m\) ...
- Codeforces 1392H - ZS Shuffles Cards(DP+打表找规律)
Codeforces 题面传送门 & 洛谷题面传送门 真·两天前刚做过这场的 I 题,今天模拟赛就考了这场的 H 题,我怕不是预言带师 提供一种奇怪的做法,来自于同机房神仙们,该做法不需要 M ...
- CF Edu Round 71
CF Edu Round 71 A There Are Two Types Of Burgers 贪心随便模拟一下 #include<iostream> #include<algor ...
- 《python编程从入门到实践》读书实践笔记(一)
本文是<python编程从入门到实践>读书实践笔记1~10章的内容,主要包含安装.基础类型.函数.类.文件读写及异常的内容. 1 起步 1.1 搭建环境 1.1.1 Python 版本选择 ...
- 【Meta】16s rRNA和16s rDNA的区别
在文章或宣传稿中经常看到两者滥用,实际上是不同的. 首先是各个字母的含义: 16S中的"S"是一个沉降系数,亦即反映生物大分子在离心场中向下沉降速度的一个指标,值越高,说明分子越大 ...
- R包开发过程记录
目的 走一遍R包开发过程,并发布到Github上使用. 步骤 1. 创建R包框架 Rsutdio --> File--> New Project--> New Directory - ...
- 如何使用csapp文件
深入理解操作系统中有个csapp.h的头文件 以下来介绍下如何使用它: 该头文件下载地址为http://download.csdn.net/detail/tzasd89812/4206284 在Ubu ...