CF46B T-shirts from Sponsor 题解
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 题解的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
随机推荐
- vip视频解析保存
无广告通用:https://vip.52jiexi.top/?url= 腾讯直解 无广告解析:https://jx.lfeifei.cn/?url= 无广告解析:https://api.steak51 ...
- 网站每日UV数据指标去重统计
package com.iexecloud.cloud.casemanager;import redis.clients.jedis.Jedis;import java.text.SimpleDate ...
- linux命令-压缩数据
linux文件压缩工具:bzip2 文件扩展名 .bz2 compress 文件扩展名 .Z linux上很少看到了 uncompress解压 gzip 文件扩展名,.gz,gzip压缩文件,gzca ...
- 超算云(GPU服务器)环境配置
最近在用并行超算云GPU服务器(中国国家网格12区)搭建毕设的环境,这里记录一下. 首先,超算云服务器的登录可以采用网页版.也可以采用客户端(超算云地址:https://cloud.paratera. ...
- java 代理模式实现代码
目录 1.静态代理 2.动态代理 1.静态代理 接口类AdminService.java接口 public interface AdminService { void update(); Object ...
- HDU 6036 Division Game
HDU 6036 Division Game 考虑每堆石头最多操作 $ \sum e $ 次,考虑设 $ f(x) $ 表示某一堆石头(最开始都是一样的)操作 $ x $ 次后变成了 $ 1 $ 的方 ...
- 生物信息Linux用户创建与配额设置
创建一个新用户,并配置使用. create_usr.sh: #/usr/bin/bash user=$1 password="123" useradd ${user} -g met ...
- Can't connect to HTTPS URL because the SSL module is not available. - skipping
今天用pip3安装第三方库的时候报了这样一个错: Can't connect to HTTPS URL because the SSL module is not available. - skipp ...
- Linux— 查看系统发布版本信息
[root@zf-test-web01-4 ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
- 学习java的第二十七天
一.今日收获 1.java完全学习手册第三章算法的3.2排序,比较了跟c语言排序上的不同 2.观看哔哩哔哩上的教学视频 二.今日问题 1.快速排序法的运行调试多次 2.哔哩哔哩教学视频的一些术语不太理 ...