codeforces 794c

本文解析了一场关于创建公司名称的博弈过程,通过贪心算法实现A、B两方策略,力求达到各自最优的名字字典序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

比赛的时候。。先yy了一发题目。然后wa了一发之后想清楚了应该怎么搞。。然后就玩了一个半钟,代码敲搓。
(主要当时竟然想到直接计数。。计数这个是个巨坑,千万不能计数啊!!!)

题目:http://codeforces.com/problemset/problem/794/C

题目大意:
有两个人想要开公司,两个人手上有相同长度为n的字符串集合,他们需要给公司搞一个名字。
公司名为长度为n的字符串,每次A玩家先从自己集合里挑一个放字符放里面,B玩家再从自己的集合里挑一个字符放里面,直到公司名完成为止。

A玩家想要公司名字典序尽量小
B玩家想要公司名字典序尽量大
A和B分别知道对方的集合里还剩下什么字符。
现在在两个人足够聪明的情况下,请问会产生出怎样的公司名。

思路:
比赛的时候思路一直是对的。。只是代码搞搓了。。orz
对于A和B:
当A集合中存在比B集合的字符要小的字符的时候,
A肯定想尽量的把小的字符放到最前面,B肯定想尽量把大的字符放到最前面。

当A集合中存在比B集合的字符要大或等于的时候,
A肯定想尽量把还需要放的字符中最大的放到最后面,
B肯定想尽量把还需要放的字符中最小的放到最后面,

就是一道贪心题。直接模拟一下字符串放置就好了。。

/*
@resources: codeforces
@date: 2017-5-13
@author: QuanQqqqq
@algorithm:
*/

#include <bits/stdc++.h>

#define ll long long
#define eps 1e-6

using namespace std;

char str1[400005],str2[400005],str3[400005];

int main(){
    gets(str1);
    gets(str2);
    int len = strlen(str1);
    sort(str1,str1 + len);
    sort(str2,str2 + len);
    int t1 = 0,t2 = len - 1,idx = len - 1;
    bool flag = true,change = false;
    for(int i = 0;i < len;i++){
        if(str1[t1] >= str2[t2] && !change){
            change = true;
            int tlen = len - i;
            int tmp1 = i % 2 ? tlen / 2 : (int)ceil(tlen / 2.0);
            int tmp2 = i % 2 ? (int)ceil(tlen / 2.0) : tlen / 2;
            tmp1--,tmp2--;
            while(tmp1--){
                t1++;
            }
            while(tmp2--){
                t2--;
            }
        }
        if(flag){
            if(change){
                str3[idx--] = str1[t1];
                t1--;
            } else {
                str3[i] = str1[t1];
                t1++;
            }
        } else {
            if(change){
                str3[idx--] = str2[t2];
                t2++;
            } else {
                str3[i] = str2[t2];
                t2--;
            }
        }
        flag = !flag;
    }
    str3[len] = '\0';
    printf("%s\n",str3);
}
### Codeforces Problem 1332C Explanation The provided references pertain specifically to problem 742B on Codeforces rather than problem 1332C. For an accurate understanding and solution approach for problem 1332C, it's essential to refer directly to its description and constraints. However, based on general knowledge regarding competitive programming problems found on platforms like Codeforces: Problem 1332C typically involves algorithmic challenges that require efficient data structures or algorithms such as dynamic programming, graph theory, greedy algorithms, etc., depending upon the specific nature of the task described within this particular question[^6]. To provide a detailed explanation or demonstration concerning **Codeforces problem 1332C**, one would need direct access to the exact statement associated with this challenge since different tasks demand tailored strategies addressing their unique requirements. For obtaining precise details about problem 1332C including any sample inputs/outputs along with explanations or solutions, visiting the official Codeforces website and navigating to contest number 1332 followed by examining section C is recommended. ```python # Example pseudo-code structure often seen in solving competitive coding questions. def solve_problem_1332C(input_data): # Placeholder function body; actual logic depends heavily on the specifics of problem 1332C. processed_result = process_input(input_data) final_answer = compute_solution(processed_result) return final_answer input_example = "Example Input" print(solve_problem_1332C(input_example)) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值