【CF #798 Div2】A

A. Lex String

题目

分析

a,b两个字符串,n,m分别是他们的长度。每次可以从他们之中取一个字符构成新串,不能连续k次从同一个字符串中取字符,求构成字典序最小的字符串。

字典序最小:优先字母顺序,并不是长度短的更小(碎碎念:每次遇到字典序最小都要写一遍)

用字符数组存储a,b两个字符串,对两个字符串按字典序排序后,从前往后像答案字符串添加。按题意模拟出答案字符串。

(碎碎念:写代码太烂真的是我的错55555)

代码

#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define guanliu ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
const ll maxn=2e5+10;
const ll mod=1e9+7;
const ll INF=0x3f3f3f3f;
const double pi=acos(-1);
char a[150],b[150],ans[300];

bool cmp(char a,char b)
{
	return a<b;
}

int main() 
{
	guanliu;
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,k;
		int cnt=0;
		cin>>n>>m>>k;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
		}
		for(int i=1;i<=m;i++)
		{
			cin>>b[i];
		}
		sort(a+1,a+1+n,cmp);
		sort(b+1,b+1+m,cmp);
		int i=1,j=1;
		int tt=0;
		int op=0;
		while(n&&m)
		{
			if(tt==k)
			{
				if(op==1)
				{
					ans[++cnt]=b[j++];
					op=2;
					tt=1;
					m--;
				}
				else {
					ans[++cnt]=a[i++];
					op=1;
					tt=1;
					n--;
				}
			}
			else {
				if(a[i]<b[j])
				{
					n--;
					ans[++cnt]=a[i++];
					if(op==1) tt++;
					else {
						op=1;
						tt=1;
					}
				}
				else {
					m--;
					ans[++cnt]=b[j++];
					if(op==2) tt++;
					else {
						op=2;
						tt=1;
					}
				}
			}
		}
		for(int i=1;i<=cnt;i++)
		{
			cout<<ans[i];
		}
		cout<<endl;
	} 
	return 0; 
}

不想补了、、、后面的想起来再补好了、、、

B. Mystic Permutation

题目

分析

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值