Codeforces 727D-T-shirts Distribution (字符串 贪心)
D. T-shirts Distribution
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this size.
During the registration, the organizers asked each of the n participants about the t-shirt size he wants. If a participant hesitated between two sizes, he could specify two neighboring sizes — this means that any of these two sizes suits him.
Write a program that will determine whether it is possible to present a t-shirt to each participant of the competition, or not. Of course, each participant should get a t-shirt of proper size:
- the size he wanted, if he specified one size;
- any of the two neibouring sizes, if he specified two sizes.
If it is possible, the program should find any valid distribution of the t-shirts.
Input
The first line of the input contains six non-negative integers — the number of t-shirts of each size. The numbers are given for the sizes S, M, L, XL, XXL, XXXL, respectively. The total number of t-shirts doesn't exceed 100 000.
The second line contains positive integer n (1 ≤ n ≤ 100 000) — the number of participants.
The following n lines contain the sizes specified by the participants, one line per participant. The i-th line contains information provided by the i-th participant: single size or two sizes separated by comma (without any spaces). If there are two sizes, the sizes are written in increasing order. It is guaranteed that two sizes separated by comma are neighboring.
Output
If it is not possible to present a t-shirt to each participant, print «NO» (without quotes).
Otherwise, print n + 1 lines. In the first line print «YES» (without quotes). In the following n lines print the t-shirt sizes the orginizers should give to participants, one per line. The order of the participants should be the same as in the input.
If there are multiple solutions, print any of them.
Examples
input
Copy
0 1 0 1 1 0
3
XL
S,M
XL,XXL
output
Copy
YES
XL
M
XXL
input
Copy
1 1 2 0 1 1
5
S
M
S,M
XXL,XXXL
XL,XXL
output
Copy
NO
题意:有六种T恤s,m,l,xl,xxl,xxxl,有些人知道自己需要的那一种T恤,有些人只知道大致的尺码范围但是给出的尺码范围是固定的只能是相邻两个尺码,然后要求你去给出一个方案使得每个人都有T恤穿 那么本题的做法就呼之欲出了,简单贪心,单个的尺码有就给,没有就不行,两个的话先从小的尺码开始找,小的先满足了然后再满足大的尺码
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register ll
#define inf 2147483647
#define lb(x) (x&(-x))
ll sz[200005],n;
template <typename T> inline void read(T& x)
{
x=0;char ch=getchar();ll f=1;
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}x*=f;
}
inline ll query(ll x){ll res=0;while(x){res+=sz[x];x-=lb(x);}return res;}
inline void add(ll x,ll val){while(x<=n){sz[x]+=val;x+=lb(x);}}//第x个加上val
map<string,ll>p;
string s[100005];
ll vis[100005];
vector<string>v;
struct wunai
{
string p;
ll num;
inline bool operator<(const wunai&a)const{
return num<a.num;
}
}ans[100005];
int main()
{
ll a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
p["S"]=a,p["M"]=b,p["L"]=c,p["XL"]=d,p["XXL"]=e,p["XXXL"]=f;
ll x,check=0;
cin>>x;
for(rg i=1;i<=x;i++)
{
cin>>s[i];
}
for(rg i=1;i<=x;i++)
{
ll flag=0;
for(rg j=0;s[i][j];j++)
{
if(s[i][j]==',')
{
flag=1;
break;
}
}
if(!flag)
{
if(p[s[i]])p[s[i]]--,vis[i]=1,ans[i].p=s[i];
else
{
check=1;
break;
}
}
}
if(check==1)
{
cout<<"NO"<<endl;
return 0;
}
//
for(rg i=1;i<=x;i++)
{
if(!vis[i])
{
if(s[i][0]=='S')
{
if(p["S"])p["S"]--,vis[i]=1,ans[i].p="S";
else if(p["M"])p["M"]--,vis[i]=1,ans[i].p="M";
else
{
check=1;
break;
}
}
}
}
if(check==1)
{
cout<<"NO"<<endl;
return 0;
}
for(rg i=1;i<=x;i++)
{
if(!vis[i])
{
if(s[i][0]=='M')
{
if(p["M"])p["M"]--,vis[i]=1,ans[i].p="M";
else if(p["L"])p["L"]--,vis[i]=1,ans[i].p="L";
else
{
check=1;
break;
}
}
}
}
if(check==1)
{
cout<<"NO"<<endl;
return 0;
}
//
for(rg i=1;i<=x;i++)
{
if(!vis[i])
{
if(s[i][0]=='L')
{
if(p["L"])p["L"]--,vis[i]=1,ans[i].p="L";
else if(p["XL"])p["XL"]--,vis[i]=1,ans[i].p="XL";
else
{
check=1;
break;
}
}
}
}
if(check==1)
{
cout<<"NO"<<endl;
return 0;
}
//
for(rg i=1;i<=x;i++)
{
if(!vis[i])
{
if(s[i][0]=='X'&&s[i][1]=='L')
{
if(p["XL"])p["XL"]--,vis[i]=1,ans[i].p="XL";
else if(p["XXL"])p["XXL"]--,vis[i]=1,ans[i].p="XXL";
else
{
check=1;
break;
}
}
}
}
if(check==1)
{
cout<<"NO"<<endl;
return 0;
}
//
for(rg i=1;i<=x;i++)
{
if(!vis[i])
{
if(s[i][0]=='X'&&s[i][1]=='X'&&s[i][2]=='L')
{
if(p["XXL"])p["XXL"]--,vis[i]=1,ans[i].p="XXL";
else if(p["XXXL"])p["XXXL"]--,vis[i]=1,ans[i].p="XXXL";
else
{
check=1;
break;
}
}
}
v.push_back(ans[i].p);
}
if(check==1)
{
cout<<"NO"<<endl;
return 0;
}
if(!check)
{
cout<<"YES"<<endl;
for(auto it:v)cout<<it<<endl;
}
return 0;
}
- 面向资源与面向活动的 Web 服务
- OpenXML 成为 ECMA标准 376
- 常用翻译技巧
- ScintillaNET 需要帮助
- Windows Live Writer工具
- WPF/XML 资源及相关开源项目
- Android应用底部导航栏(选项卡)实例
- 有关 ASMX 2.0、WSE 3.0 和 WCF 的内容
- 微信小程序游戏其实一般,我也就站在寒风里玩了一个小时
- beagle MONO 应用的desktop search
- Python3与OpenCV3.3 图像处理(一)-环境搭建与简单DEMO
- winform中利用正则表达式得到有效的电话/手机号
- 浅述RDF,畅想一下FOAF应用
- 数据源控件参数类Parameter
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法