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;
}
- 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 数组属性和方法
- 轻松学Pytorch-实现自定义对象检测器
- Elasticsearch 升级 7.x 版本后,我感觉掉坑里了!
- 【一起学系列】之适配器模式:还有外观模式呢
- 【翻译】200行代码讲透RUST FUTURES (5)
- Unable to preventDefault inside passive event listener
- js 停止事件冒泡 阻止浏览器的默认行为(阻止a标签跳转 )
- EmitMapper的使用小结
- js .map方法
- 【一起学系列】之模板方法:写SSO我只要5分钟
- ConcurrentDictionary线程不安全么,你难道没疑惑,你难道弄懂了么?
- 【一起学系列】之迭代器&组合:虽然有点用不上啦
- 移动端touch事件影响click事件以及在touchmove添加preventDefault导致页面无法滚动的解决方法
- 使用ActionFilterAttribute 记录 WebApi Action 请求和返回结果记录
- scipy.stats连续分布的基本操作
- InvocationHandler中invoke方法中的第一个参数proxy的用途