Codeforces 727 D T-shirts Distribution
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的更多相关文章
- codeforces 798 D. Mike and distribution
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces 798 D. Mike and distribution(贪心+思维)
题目链接:http://codeforces.com/contest/798/problem/D 题意:给出两串长度为n的数组a,b,然后要求长度小于等于n/2+1的p数组是的以p为下表a1-ap的和 ...
- 【codeforces 798D】Mike and distribution
[题目链接]:http://codeforces.com/contest/798/problem/D [题意] 让你选一个下标集合 p1,p2,p3..pk 使得2*(a[p1]+a[p2]+..+a ...
- Codeforces 727 F. Polycarp's problems
Description 有一个长度为 \(n\) 有正负权值的序列,你一开始有一个值,每次到一个权值就加上,最少需要删掉多少数值才能到序列末尾.\(n \leqslant 750,m \leqslan ...
- 4.30-5.1cf补题
//yy:拒绝转载!!! 悄悄告诉你,做题累了,去打两把斗地主就能恢复了喔~~~ //yy:可是我不会斗地主吖("'▽'") ~~~那就听两遍小苹果嘛~~~ 五一假期除了花时间建模 ...
- 【codeforces 727D】T-shirts Distribution
[题目链接]:http://codeforces.com/problemset/problem/727/D [题意] 给你6种尺寸的衣服; 他们的尺码依次为S, M, L, XL, XXL, XXXL ...
- Codeforces Gym 100425A Luggage Distribution 二分 数学
A - Luggage DistributionTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/c ...
- 【算法系列学习】codeforces D. Mike and distribution 二维贪心
http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...
- 7-27 Codeforces Round #499 (Div. 2)
C. Fly 链接:http://codeforces.com/group/1EzrFFyOc0/contest/1011/problem/C 题型:binary search .math. 题意:总 ...
随机推荐
- ubuntu 重启 nginx 失败,* Restarting nginx nginx ...fail!
ubuntu 重启 nginx 失败,* Restarting nginx nginx ...fail! 执行 nginx 重启服务时,提示失败如下: $ sudo service ngi ...
- Runner站立会议06
开会时间:21.10~21.30 地点:基教负一 今天做了什么:日历布局,晚善日历 明天准备做什么:完善日历界面 遇到的困难:暂无 燃尽图: 会议图:
- Java排序算法——冒泡排序
import java.util.Arrays; //================================================= // File Name : Bubble_S ...
- yourphp的sql语句
1.插入单条数据 $data[0]['cardid'] = $_POST['cardid']; $data[0]['name'] = $_POST['name']; $data[0]['mobile' ...
- js生成一个以零开头的八位数并且依次递增
条件:1八位数:2.以领开头:3.末尾要依次递增 <script type="text/javascript">function Account(num,a){ // ...
- ASP.NET WebForm中用async/await实现异步
1. 在.aspx中添加异步标记 <%@ Page Language="C#" Async="true"%> 2. 在.aspx.cs或者.ascx ...
- Autofac和DynamicProxy2搭配实现Aop动手训练
http://www.cnblogs.com/zhengwl/p/5433181.html Aop含义:aspect-oriented programming 实现工具介绍 Autofac是一个比较流 ...
- IIS 8.5 伪静态去掉index.php thinkphp 3.2.2
因为测试都是在win下开发的 win8.1企业版 II8.5 首先安装 Thinkphp 3.2.2 URL Rewrite Module 2.0 http://www.iis.net/downlo ...
- NancyFx中使用自带的IOC容器
/// <summary> /// Cors扩展 /// </summary> public static class IPipelinesExtensions { /// & ...
- PHP中spl_autoload_register()函数
spl_autoload_register — 注册给定的函数作为 __autoload 的实现 官方地址:http://php.net/manual/zh/function.spl-autoload ...