Content

有一家服装店,有 \(\texttt{S}\) 码的衣服 \(n_S\) 件、\(\texttt{M}\) 码的衣服 \(n_M\) 件,\(\texttt{L}\) 码的衣服 \(n_L\) 件,\(\texttt{XL}\) 码的衣服 \(n_{XL}\) 件,\(\texttt{XXL}\) 码的衣服 \(n_{XXL}\) 件。

有 \(k\) 个人依次进来买衣服,每个人都有自己期望的尺码。如果服装店里面刚好有这个尺码的衣服,TA 就会拿上这件衣服离开,否则 TA 会选择尽可能接近自己的期望尺码的衣服(如果在这样的情况下有多种选择,则选择尺码较大的)。求这 \(k\) 个人最后各拿了什么尺码的衣服。

数据范围:\(1\leqslant n_S,n_M,n_L,n_{XL},n_{XXL}\leqslant 1000,1\leqslant k\leqslant n_S+n_M+n_L+n_{XL}+n_{XXL}\leqslant 1000\)。

Solution

这题目模拟就好,就是代码稍微长了一些。

我们先看是否有每个人的期望尺码的衣服,如果有那就直接选择,否则分别向大尺码和小尺码依次遍历,大尺码先遍历到就选择大尺码,小尺码先遍历到就选择小尺码。因为数据的特殊性,无需判断是否有足够的衣服。

Code

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std; int sze[7], k;
string str;
const string ans[6] = {"", "S", "M", "L", "XL", "XXL"}; int main() {
for(int i = 1; i <= 5; ++i) scanf("%d", &sze[i]);
scanf("%d", &k);
while(k--) {
cin >> str;
if(str == "S") {
if(sze[1]) {puts("S"); sze[1]--;}
else {
int cur = 1;
while(1) {
cur = min(5, cur + 1);
if(sze[cur]) {
cout << ans[cur] << endl;
sze[cur]--;
break;
}
}
}
} else if(str == "M") {
if(sze[2]) {puts("M"); sze[2]--;}
else {
int curl = 2, curr = 2;
while(1) {
curl = max(1, curl - 1), curr = min(5, curr + 1);
if(sze[curr]) {
cout << ans[curr] << endl;
sze[curr]--;
break;
} else if(sze[curl]) {
cout << ans[curl] << endl;
sze[curl]--;
break;
}
}
}
} else if(str == "L") {
if(sze[3]) {puts("L"); sze[3]--;}
else {
int curl = 3, curr = 3;
while(1) {
curl = max(1, curl - 1), curr = min(5, curr + 1);
if(sze[curr]) {
cout << ans[curr] << endl;
sze[curr]--;
break;
} else if(sze[curl]){
cout << ans[curl] << endl;
sze[curl]--;
break;
}
}
}
} else if(str == "XL") {
if(sze[4]) {puts("XL"); sze[4]--;}
else {
int curl = 4, curr = 4;
while(1) {
curl = max(1, curl - 1), curr = min(5, curr + 1);
if(sze[curr]) {
cout << ans[curr] << endl;
sze[curr]--;
break;
} else if(sze[curl]) {
cout << ans[curl] << endl;
sze[curl]--;
break;
}
}
}
} else if(str == "XXL") {
if(sze[5]) {puts("XXL"); sze[5]--;}
else {
int cur = 5;
while(1) {
cur = max(1, cur - 1);
if(sze[cur]) {
cout << ans[cur] << endl;
sze[cur]--;
break;
}
}
}
}
}
}

CF46B T-shirts from Sponsor 题解的更多相关文章

  1. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  2. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  3. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  4. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  5. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  6. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  7. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  8. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

  9. CF100965C题解..

    求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...

随机推荐

  1. 面向对象中static的理解(1)

    class 对象名字{ data members; static data members; function members; static function members; } 每创建一个对象, ...

  2. emoji表情等特殊字符处理和存储的两个方案

    方案1.改数据库配置 使之支持emoji表情等特殊字符,小公司或者个人开发还好,大公司用此方案代价较大. 以mysql为例,改配置方法参考:https://blog.csdn.net/u0107373 ...

  3. git使用小技巧

    1. 合并一个分支的某次提交到另一个分支上 例如 将dev的某次提交 asfdiwehfsalkdnva872383 合并到master # git checkout master # git che ...

  4. 『学了就忘』Linux权限管理 — 56、不可改变位权限(chattr)

    目录 1.命令格式 2.查看文件系统属性chattr权限 3.示例 文件系统属性chattr权限,也叫不可改变位权限,该权限没有风险,但是他能限制root用户. 1.命令格式 [root@localh ...

  5. Go IF 条件语句

    条件语句需要开发者通过指定一个或多个条件,并通过测试条件是否为 true 来决定是否执行指定语句,并在条件为 false 的情况在执行另外的语句. 以下是在大多数编程语言中发现的典型条件语句的一般形式 ...

  6. Redis概述以及Linux安装

    Redis 概述 Redis是什么 Redis,Remote Dictionary Server,远程字典服务.是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.key-v ...

  7. Codeforces 1455G - Forbidden Value(map 启发式合并+DP)

    Codeforces 题面传送门 & 洛谷题面传送门 首先这个 if 与 end 配对的结构显然形成一个树形结构,考虑把这棵树建出来,于是这个程序的结构就变为,对树进行一遍 DFS,到达某个节 ...

  8. Git常用操作(二)

    仓库拉取 git clone XXX 修改仓库链接 $ git config -l # 显示coding列表 $ git config --get remote.origin.url # 返回orig ...

  9. GWAS数据分析常见的202个问题?

    生信其实很简单,就是用别人的工具调参就行了.生信也很折腾,哪一步都可能遇到问题,随时让你疯掉(老辩证法了~).但是,你遇到的问题大部分人也都经历过.这时,检索技能就显得很重要了.平时Biostar和S ...

  10. 毕业设计之LVS+keealive 负载均衡高可用实现

    环境介绍 centos6.9最小化安装 主机名 IPADDR lvsA.load.quan.bbs 192.168.111.131 lvsB.load.quan.bbs 192.168.111.132 ...