Codeforces Round #414 C.Naming Company(贪心)

C. Naming Company
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.

To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.

For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :

Initially, the company name is ???.

Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.

Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.

Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.

In the end, the company name is oio.

Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?

A string s = s1s2...sm is called lexicographically smaller than a string t = t1t2...tm (where s ≠ t) if si < ti where i is the smallest index such that si ≠ ti. (so sj = tj for all j < i)

Input

The first line of input contains a string s of length n (1 ≤ n ≤ 3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.

The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.

Output

The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.

Examples
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
Note

One way to play optimally in the first sample is as follows :

  • Initially, the company name is ???????.
  • Oleg replaces the first question mark with 'f'. The company name becomes f??????.
  • Igor replaces the second question mark with 'z'. The company name becomes fz?????.
  • Oleg replaces the third question mark with 'f'. The company name becomes fzf????.
  • Igor replaces the fourth question mark with 's'. The company name becomes fzfs???.
  • Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??.
  • Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?.
  • Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.

For the second sample, no matter how they play, the company name will always be xxxxxx.

分析:

由题意,第一个人要构造最小的字符串,而第二个人要构造最大的字符串。

当n为奇数时 集合一中要用到n/2+1个字母 ,n为偶数时用到n/2个字母,那么我们可以只保留字典序较小的字母

集合二则只保留字典序较大的字母轮到集合一取数的时候

当集合一中的最小的字母小于集合二中最大的字母时,则将该字母放在字符串的下一个位置,否则,将集合一中最大的字母放在字符串从后往前数的下一个位置。轮到集合二取数的时候

当集合二中最大的字母大于集合一中最小的字母时,将该字母放在字符串的下一个位置,否则,将集合二中最小的字母放在字符串从后往前数的下一个位置。

这样就能构造出符合的字符串。

代码如下:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include<cstring>
using namespace std;
char a[300010];
char b[300010];
char res[300010];
int cmp(int x,int y)
{
  return x>y;
}
int main()
{
	int na,nb,cnt,pa,qa,pb,qb,l,r,L;
	while(scanf("%s%s",a,b)!=EOF)
	{
		cnt=0;
		na=strlen(a);
		L=na;
		nb=strlen(b);
		sort(a,a+na);
		sort(b,b+nb,cmp);
		if(na%2==1)
		na=na/2+1;
		else
		na=na/2;
		nb=L-na;
		pa=0;
		qa=na-1;
		pb=0;
		qb=nb-1;
		l=0;
		r=L-1;
		for(int i=0;i<L;i++)
		{
		   if(i%2==0)
		   {
		   	 if(a[pa]>=b[pb])
		   	  res[r--]=a[qa--];
		   	  else
		   	  res[l++]=a[pa++];
		   }
		   else
		   {
		   	  if(a[pa]>=b[pb])
		   	  	res[r--]=b[qb--];
		   	  else
		   	  res[l++]=b[pb++];
		   }
		}
		res[L]='\0';
		printf("%s",res);
		printf("\n");
	}
	return 0;
}

  

转载于:https://www.cnblogs.com/a249189046/p/6880420.html

基于MMSkeleton工具包中的ST-GCN模型实现一种基于动态拓扑图的人体骨架动作识别算法python源码+使用说明.zip 改进ST-GCN模型的骨架拓扑图构建部分,使用持续学习思想动态构建人体骨架拓扑图. 将具有多关系特性的人体骨架序列数据重新编码为关系三元组, 并基于长短期记忆网络, 通过解耦合的方式学习特征嵌入. 当处理新骨架关系三元组时, 使用部分更新机制 动态构建人体骨架拓扑图, 将拓扑图送入ST-GCN进行动作识别。 运行MMSKeleton工具包参考[GETTING_STARTED.md](./doc/GETTING_STARTED.md) - 单独使用ST-GCN模型进行人体动作识别参考[START_RECOGNITION.md](./doc/START_RECOGNITION.md) - 训练基于动态拓扑图的人体骨架动作识别算法 ``` shell cd DTG-SHR python ./mmskeleton/fewrel/test_lifelong_model.py ``` - 测试基于动态拓扑图的人体骨架动作识别算法 ``` shell cd DTG-SHR python ./mmskeleton/fewrel/train_lifelong_model.py ``` - 可视化算法运行结果 基于web server搭建前端 [[参考]](https://blog.csdn.net/gzq0723/article/details/113488110) 1、前端模块:包含 'static与'templates'文件夹为界面展示相关的代码。 templates里面包含了两个html的结构文档,用来定义浏览器的显示界面。 static里面的css和img用来修饰界面。 2、服务模块: servel.py里面是web服务的一个业务逻辑。 运行算法性能可视化web服务 ``` shell cd DTG-SHR python ./server.py ``` 【备注】 1、该资源内项目代码百分百可运行,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值