Codeforces 727D-T-shirts Distribution
来源:互联网 发布:秃鹰配件名称及数据 编辑:程序博客网 时间:2024/05/15 17:33
原题链接
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 XXXLyou 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.
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 sizesS, 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.
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.
0 1 0 1 1 03XLS,MXL,XXL
YESXLMXXL
1 1 2 0 1 15SMS,MXXL,XXXLXL,XXL
NO
统计每种衣服的数量,用cnt数组表示。先为只有一种选择的人分配衣服,更新cnt[].最后剩下的人每个人对衣服的选择有两个,总共五种选择,其中五种选择中S衣服只出现一次"S,M"那么把所有S的衣服分配给这种选择的人,不够的话用M衣服来补。那么剩下四种选择,其中M衣服只出现一次"M.L",分配方式一样
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <map>#include <vector>#define maxn 5005#define MOD 1000000007using namespace std;typedef long long ll;char s1[5][10] = {"S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL"};char s2[6][10] = {"S", "M", "L", "XL", "XXL", "XXXL"}; char s3[100005][10];int cnt[6];int main(){//freopen("in.txt", "r", stdin); for(int i = 0; i < 6; i++) scanf("%d", cnt+i);int n;scanf("%d", &n); for(int i = 0; i < n; i++){scanf("%s", s3[i]);for(int j = 0; j < 6; j++){if(strcmp(s3[i], s2[j]) == 0){cnt[j]--;break;}}}for(int i = 0; i < 6; i++){if(cnt[i] < 0){puts("NO");return 0;}}for(int i = 0; i < 5; i++){for(int j = 0; j < n; j++){if(strcmp(s1[i], s3[j]) == 0){if(cnt[i] > 0){cnt[i]--;strcpy(s3[j], s2[i]);}else if(cnt[i+1] > 0){cnt[i+1]--;strcpy(s3[j], s2[i+1]);}else{puts("NO");return 0;}}}}puts("YES");for(int i = 0; i < n; i++) puts(s3[i]);return 0;}
- Codeforces 727D-T-shirts Distribution
- CF727D:D. T-shirts Distribution(贪心)
- Technocup 2017 - Elimination Round 1 (Rated for Div. 2) D. T-shirts Distribution 贪心、flows
- CodeForces 46B T-shirts from Sponsor
- Codeforces702F. T-Shirts
- Codeforces 798D Mike and distribution 构造
- codeforces 798D Mike and distribution
- codeforces 798D Mike and distribution
- CodeForces 798D Mike and distribution
- Codeforces-798D. Mike and distribution
- Supply clothes,D&G jeans,polo t-shirts,bape hoodies,prada jackets, sports wear(NBA,MLB,NHL,NFL)
- Codeforces 798D Mike and distribution(二维贪心)
- Codeforces-798D-Mike and distribution(贪心)
- CF-Codeforces Round #410 (Div. 2)-D-Mike and distribution
- Codeforces Round #410 (Div. 2) D. Mike and distribution 思维
- Codeforces Round #410 (Div. 2) D. Mike and distribution(贪心)
- codeforces 798 D. Mike and distribution 二维贪心
- Codeforces Round #410 Div2 D Mike and distribution
- android:通知
- Mark-Down-语法
- 技术盲区
- JFinal 安装之初体验
- ListView控件中插入一组图片
- Codeforces 727D-T-shirts Distribution
- linux网络编程之socket(五):tcp流协议产生的粘包问题和解决方案
- java 内部类
- 让年轻人在年轻时做该做的事
- Android-Service
- 算法练习13
- Swing布局管理器
- java io -- FileInputStream
- Email已死?