Description

有 \(6\) 种尺码的衣服,有的人只适合 \(1\) 种衣服,有的人适合相邻的 \(2\) 种,问是否存在合法方案,并输出.

Sol

贪心.

首先,只适合 \(1\) 种衣服的直接减去就好了,如果个数小于 \(0\) 了直接不合法.

然后考虑适合两种衣服的.首先就是,可以跑网络流或者二分图匹配.

一共就有 \(5\) 种情况 \((1,2),(2,3),(3,4),(4,5),(5,6)\) .

很容易的,我们就发现它其实可以贪心...

对于第 \(1\) 种情况,如果 \(1\) 号衣服有剩余的,那么就使用,然后不够就使用下一个即可.

以此类推.

排一下序,统计一下个数直接贪心就好.

Code

#include<cstdio>
#include<cstring>
#include<utility>
#include<algorithm>
#include<iostream>
using namespace std; #define mpr(a,b) make_pair(a,b)
const int N = 100005; int n,m,a[10],b[10];
int g[N];
pair< pair<int,int> , int> p[N];
pair<int,int> q[10];
pair<int,int> ans;
int sum[10]; int kind(char a[]){
if(a[0]=='S') return 1;
if(a[0]=='M') return 2;
if(a[0]=='L') return 3;
if(strlen(a)==2) return 4;
if(strlen(a)==3) return 5;
return 6;
} int main(){
for(int i=1;i<=6;i++) cin>>a[i],b[i]=a[i];
cin>>n;
// cout<<n<<endl;
for(int i=1;i<=n;i++){
char ch=getchar();
char tmp[10];int l=0;
memset(tmp,0,sizeof(tmp));
while(ch>'Z'||ch<'A') ch=getchar();
while(ch>='A'&&ch<='Z') tmp[l++]=ch,ch=getchar(); if(ch==','){
int t1=kind(tmp),t2;
ch=getchar(),l=0,memset(tmp,0,sizeof(tmp));
while(ch>'Z'||ch<'A') ch=getchar();
while(ch>='A'&&ch<='Z') tmp[l++]=ch,ch=getchar();
t2=kind(tmp);
if(t1>t2) swap(t1,t2);
p[++m]=mpr(mpr(t1,t2),i);
}else{
a[kind(tmp)]--,b[kind(tmp)]--;g[i]=kind(tmp);
if(a[kind(tmp)]<0){ puts("NO");return 0; }
}
}
sort(p+1,p+m+1); for(int i=1;i<=5;i++) q[i]=mpr(i,i+1); for(int i=1;i<=m;i++) for(int j=1;j<=5;j++) if(p[i].first==q[j]) sum[j]++; for(int i=1;i<=6;i++) if(a[i]<0){ puts("NO");return 0; } for(int i=1;i<=5;i++){
if(a[i]>=sum[i]) a[i]-=sum[i];
else{
a[i+1]-=sum[i]-a[i],a[i]=0;
}
for(int j=1;j<=6;j++) if(a[j]<0){ puts("NO");return 0; }
}
for(int i=1;i<=6;i++) if(a[i]<0){ puts("NO");return 0; }
puts("YES");
for(int i=1;i<=m;i++){
for(int j=1;j<=5;j++) if(p[i].first==q[j]){
if(b[j]>a[j]) g[p[i].second]=j,b[j]--;
else g[p[i].second]=j+1,b[j+1]--;
}
}
for(int i=1;i<=n;i++){
switch(g[i]){
case 1:puts("S");break;
case 2:puts("M");break;
case 3:puts("L");break;
case 4:puts("XL");break;
case 5:puts("XXL");break;
case 6:puts("XXXL");break;
}
} return 0;
}

  

Codeforces 727 D T-shirts Distribution的更多相关文章

  1. codeforces 798 D. Mike and distribution

    D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  2. codeforces 798 D. Mike and distribution(贪心+思维)

    题目链接:http://codeforces.com/contest/798/problem/D 题意:给出两串长度为n的数组a,b,然后要求长度小于等于n/2+1的p数组是的以p为下表a1-ap的和 ...

  3. 【codeforces 798D】Mike and distribution

    [题目链接]:http://codeforces.com/contest/798/problem/D [题意] 让你选一个下标集合 p1,p2,p3..pk 使得2*(a[p1]+a[p2]+..+a ...

  4. Codeforces 727 F. Polycarp's problems

    Description 有一个长度为 \(n\) 有正负权值的序列,你一开始有一个值,每次到一个权值就加上,最少需要删掉多少数值才能到序列末尾.\(n \leqslant 750,m \leqslan ...

  5. 4.30-5.1cf补题

    //yy:拒绝转载!!! 悄悄告诉你,做题累了,去打两把斗地主就能恢复了喔~~~ //yy:可是我不会斗地主吖("'▽'") ~~~那就听两遍小苹果嘛~~~ 五一假期除了花时间建模 ...

  6. 【codeforces 727D】T-shirts Distribution

    [题目链接]:http://codeforces.com/problemset/problem/727/D [题意] 给你6种尺寸的衣服; 他们的尺码依次为S, M, L, XL, XXL, XXXL ...

  7. Codeforces Gym 100425A Luggage Distribution 二分 数学

    A - Luggage DistributionTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...

  8. 【算法系列学习】codeforces D. Mike and distribution 二维贪心

    http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...

  9. 7-27 Codeforces Round #499 (Div. 2)

    C. Fly 链接:http://codeforces.com/group/1EzrFFyOc0/contest/1011/problem/C 题型:binary search .math. 题意:总 ...

随机推荐

  1. C#--副线程调用主线程的控件

    1.取消线程安全保护模式     在程序初始化的时候对要操作的控件设置下面的属性:     System.Windows.Forms.Control.CheckForIllegalCrossThrea ...

  2. FBX .NET

    https://github.com/returnString/ManagedFBX http://fbx.codeplex.com/ http://code.openhub.net/project? ...

  3. ecshop程序结构说明

    文件夹说明 名称 备注(作用或意义) 根目录 前台程序文件 admin 后台程序文件 admin/help 功能的帮助文件 admin/images 后台页面用图片 admin/includes 后台 ...

  4. IntelliJ IDEA 远程调试

    远程调试服务器是一个比较实用的技巧,以便我们能够迅速定位线上问题.本文会介绍如何在IntelliJ IDEA中进行远程调试. 配置IntelliJ IDEA 选择Edit Configurations ...

  5. “mybatis 中使用foreach 传

    为了帮助网友解决“mybatis 中使用foreach 传”相关的问题,中国学网通过互联网对“mybatis 中使用foreach 传”相关的解决方案进行了整理,用户详细问题包括:mybatismap ...

  6. vim 中 也可以 直接安装 emmet 直接使用zen coding 生成 l指定个数的 lorem ipsum文字.

    超链接的写法: 当作为链接的文字, 比较长时, 整个作为链接 就显得不是 很适合. 可以取其中的某一个单词 作为 超链接的 关键字:如: click here to continue emmet中如何 ...

  7. html css 网络 页面布局 颜色 参考 拾取器网址

    http://blog.163.com/wujinhongisme@126/blog/static/3613698020095115919389/ ========================== ...

  8. winScp上传文件时,如何过滤制定文件

    在用winScp上传文件时,有些文件不想上传到服务器上.怎么办呢? 比如我希望过滤.svn .git文件和目录怎么操作呢? 第一步:在菜单上选中选项,点击选项. 第二步,点击传输->编辑 第三步 ...

  9. Genymotion启动时出现错误virtualization engine not found

    打开VirtualBox,管理-全局设定,网络,仅主机“Host-only”网络,需要的设置如下

  10. Python IDE: Eclipse + PyDev

    依次下载 Python.Django(并安装好).JAVA.Eclipse.Eclipse 中文语言包(http://www.eclipse.org/babel/downloads.php).PyDe ...