「杂题乱刷2」CF1506E Restoring the Permutation

duel 到的。

题目链接

CF727D (luogu)

CF727D (codeforces)

解题思路

首先只能选一个尺码的人直接给就是了,这样我们就只用考虑选两个尺码的人了。

因为适合穿两个尺码衣服的人的适合穿的两个尺码是相邻的,因此我们直接从小到大按照有两个尺码的人排序,再将剩下的衣服大小从小到大排序,然后依次将衣服给这些人就可以了。

这里我用了桶排,时间复杂度 \(O(n)\)

参考代码

点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
打 cf 不要用 umap!!!

记住,rating 是身外之物。

该冲正解时冲正解!

Problem:

算法:

思路:

*/
#include<bits/stdc++.h>
using namespace std;
//#define map unordered_map
#define re register
#define ll long long
#define forl(i,a,b) for(re ll i=a;i<=b;i++)
#define forr(i,a,b) for(re ll i=a;i>=b;i--)
#define forll(i,a,b,c) for(re ll i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(re ll i=a;i>=b;i-=c)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid ((l+r)>>1)
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) (x&-x)
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define db long double
#define ull unsigned long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
#define aty cout<<"Yes\n";
#define atn cout<<"No\n";
#define cfy cout<<"YES\n";
#define cfn cout<<"NO\n";
#define xxy cout<<"yes\n";
#define xxn cout<<"no\n";
#define printcf(x) x?cout<<"YES\n":cout<<"NO\n";
#define printat(x) x?cout<<"Yes\n":cout<<"No\n";
#define printxx(x) x?cout<<"yes\n":cout<<"no\n";
#define maxqueue priority_queue<ll>
#define minqueue priority_queue<ll,vector<ll>,greater<ll>>
ll t;
ll a[10];
ll pw(ll x){
	return 1ll<<x;
}
string s;
ll n,b[100010];
ll ans[100010];
void print(ll x)
{
	if(!x)
		cout<<"Failed.\n";
	else if(x==1)
		cout<<"S\n";
	else if(x==2)
		cout<<"M\n";
	else if(x==3)
		cout<<"L\n";
	else
	{
		forl(i,1,x-3)
			cout<<"X";
		cout<<"L\n";
	}
}
/*
1 2 4 4 1 1
10
XL
XL
S,M
L
M,L
L
S,M
M
XL,XXL
XL
*/
void solve()
{
	forl(i,0,5)
		cin>>a[i];
	cin>>n;
	forl(i,1,n)
	{
		cin>>s;
		ll pd=0;
		forl(j,0,(ll)s.size()-1)
			if(s[j]==',')
				pd=1;
		if(!pd)
		{
			if(s=="S")
				b[i]|=pw(0);
			else if(s=="M")
				b[i]|=pw(1);
			else if(s=="L")
				b[i]|=pw(2);
			else if(s=="XL")
				b[i]|=pw(3);
			else if(s=="XXL")
				b[i]|=pw(4);
			else
				b[i]|=pw(5);
		}
		else
		{
			string S="";
			ll wz=0;
			forl(j,0,(ll)s.size()-1)
			{
				if(s[j]!=',')
					S+=s[j];
				else
				{
					wz=j;
					break;
				}
			}
			if(S=="S")
				b[i]|=pw(0);
			else if(S=="M")
				b[i]|=pw(1);
			else if(S=="L")
				b[i]|=pw(2);
			else if(S=="XL")
				b[i]|=pw(3);
			else if(S=="XXL")
				b[i]|=pw(4);
			else
				b[i]|=pw(5);
			S="";		
			forl(j,wz+1,(ll)s.size()-1)
			{
				if(s[j]!=',')
					S+=s[j];
				else
				{
					wz=j;
					break;
				}
			}
			if(S=="S")
				b[i]|=pw(0);
			else if(S=="M")
				b[i]|=pw(1);
			else if(S=="L")
				b[i]|=pw(2);
			else if(S=="XL")
				b[i]|=pw(3);
			else if(S=="XXL")
				b[i]|=pw(4);
			else
				b[i]|=pw(5);	
		}
	}
	forl(i,0,5)
		forl(j,1,n)
			if(b[j]==pw(i))
			{
				if(!a[i])
				{
					cfn;
					return ;
				}
				a[i]--;
				ans[j]=i+1;
			}
	forl(i,0,5)
	{
		forl(j,1,n)
			if(!ans[j])
				if((b[j]&pw(i))==pw(i) && b[j]<pw(i)*2)
					if(a[i])
						a[i]--,ans[j]=i+1;
		forl(j,1,n)
			if(!ans[j])
				if((b[j]&pw(i))==pw(i))
					if(a[i])
						a[i]--,ans[j]=i+1;		
	}
//	cout<<b[7]<<endl;
	forl(i,1,n)
		if(ans[i]==0)
		{
			cfn;
			return ;
		}
	cfy;
	forl(i,1,n)
		print(ans[i]);
}
int main()
{
	IOS;
	t=1;
 //	cin>>t;
	while(t--)
		solve();
    /******************/
	/*while(L<q[i].l) */
	/*    del(a[L++]);*/
	/*while(L>q[i].l) */
	/*    add(a[--L]);*/
	/*while(R<q[i].r) */
	/*	  add(a[++R]);*/
	/*while(R>q[i].r) */
	/*    del(a[R--]);*/
    /******************/
	QwQ;
}
posted @ 2024-07-14 13:49  wangmarui  阅读(7)  评论(0编辑  收藏  举报