【codeforces 727D】T-shirts Distribution
【题目链接】:http://codeforces.com/problemset/problem/727/D
【题意】
给你6种尺寸的衣服;
他们的尺码依次为S, M, L, XL, XXL, XXXL;
给你每种衣服的件数;
以及每个人想要的衣服种类;
(但有些人可能不知道自己要的是哪一种衣服,则他们对这相邻的两种衣服都接受)
然后让你去分配这6种衣服;
让每个人都满意;
【题解】
对于单个选择的;直接让他们满意;
给他们想要的;
对于相邻选择的;
考虑”S,M”,”M,L”,”L,XL”,”XL,XXL”,”XXL,XXXL”
可以看到S只有一种人要,其他的人都不会要S了
所以对于选择S、M的,
优先把S衣服给它;
如果S不够了,再分M的;
如果不行、就无解;
这样我们又把S、M的排除掉了,
对于剩下的
“M,L”,”L,XL”,”XL,XXL”,”XXL,XXXL”
M也只有一种人要;
则对于M、L也优先分配M;
不足的再用L补
很棒的贪心
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100;
const string idx[11]={"S","M","L","XL","XXL","XXXL","S,M","M,L","L,XL","XL,XXL","XXL,XXXL"};
int now[6],n,p[N],ans[N];
string s;
int zzk(string t)
{
rep1(i,0,10)
if (idx[i]==t)
return i;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
rep1(i,0,5) cin>>now[i];
cin>>n;
rep1(i,1,n)
{
cin >> s;
rep1(j,0,10)
if (s == idx[j])
p[i] = j;
}
rep1(i,1,n)
if (p[i]<=5)
{
if (now[p[i]])
{
now[p[i]]--;
ans[i] = p[i];
}
else
return cout << "NO"<<endl,0;
}
rep1(k,6,10)
{
int pos = idx[k].find(',',0);
int p1 = zzk(idx[k].substr(0,pos)),p2 = zzk(idx[k].substr(pos+1,10));
//cout <<p1<<' '<<p2<<endl;
rep1(i,1,n)
if (p[i]==k)
{
if (now[p1])
{
now[p1]--;
ans[i] = p1;
continue;
}
if (now[p2])
{
now[p2]--;
ans[i] = p2;
continue;
}
return cout << "NO"<<endl,0;
}
}
cout <<"YES"<<endl;
rep1(i,1,n)
cout << idx[ans[i]] << endl;
return 0;
}
【codeforces 727D】T-shirts Distribution的更多相关文章
- 【codeforces 798D】Mike and distribution
[题目链接]:http://codeforces.com/contest/798/problem/D [题意] 让你选一个下标集合 p1,p2,p3..pk 使得2*(a[p1]+a[p2]+..+a ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【23.33%】【codeforces 557B】Pasha and Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
随机推荐
- 原型设计模式prototype-构造js自己定义对象
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【函数式】Monads模式初探——Endofunctor
自函子 自函子(Endofunctor)是一个将范畴映射到自身的函子(A functor that maps a category to itself). 函子是将一个范畴转换到另一个范畴.所以自函子 ...
- Android动态部署五:怎样从插件apk中启动Service
转载请注明出处:http://blog.csdn.net/ximsfei/article/details/51072332 github地址:https://github.com/ximsfei/Dy ...
- Android 删除新版安卓fragment_main.xml
在新版本号的ADT中,创建androidproject时默认会产生两个xml文件--fragment_main和activity_main. 个人建议把fragment_main这个文件删除掉 1)将 ...
- luogu3942 将军令 贪心
题目大意:给你一个地图(树),共有1~n个驿站(点),编号分别为1~n,告诉你第ui个驿站与第vi个驿站有一条长度为1的路(边),每个小队(可以放在任意驿站上)最多有k的覆盖长度,问最多要放置多少个小 ...
- open Command window here
http://www.sevenforums.com/tutorials/134831-open-command-window-here-add-remove.html 按照教程里面,下载一个脚本 需 ...
- 【NOIP 2011】 计算系数
[题目链接] https://www.luogu.org/problemnew/show/P1313 [算法] 二项式定理 [代码] #include<bits/stdc++.h> usi ...
- Spring Boot:Exception parsing document: template="index", line 7 - column 3
转自:https://blog.csdn.net/u010429286/article/details/75447561
- Java多线程编程那些事:volatile解惑--转
http://www.infoq.com/cn/articles/java-multi-thread-volatile/ 1. 前言 volatile关键字可能是Java开发人员“熟悉而又陌生”的一个 ...
- 谷歌vimium配置
谷歌不得不说真的是一个非常好用的浏览器(之前用的浏览器真的好low),推荐一款非常极客的的插件vimium,让你使用彻底告别鼠标,瞬间感觉高大上... 默认配置: j: 向下细微滚动窗口. k:向上 ...