Codeforces Round #414 C. Naming Company 贪心
来源:互联网 发布:淘宝线下推广计划 编辑:程序博客网 时间:2024/06/06 18:11
**题目链接: Naming Company
题目大意
两个人分别有一个长度为len 的字符串(有重复字符), 两个人交替往一个字符串里用自己字符串里的字符填字符(一个字符用过了就不能再用了), 第一个人要让得到的字符串字典序尽可能小, 第二个人要让字典序尽可能大
两个人都以最优方案填字符, 输出最后的到的字符
思路
一般情况下, 第一个一定是用自己剩下的字符中最小的字符填到最前面, 另一个人一定是用最大的字符填到最前面
但如果第一个发现第二个人所有字符都比自己的小或相等, 这时候就要把前面的位置留给第二个人填, 这样才最优, 自己则把自己剩下的最大的字符填到最后面
另一个人同理
代码
#include <bits/stdc++.h>using namespace std;const int MAXN = 4 * 1E5;char s1[MAXN], s2[MAXN], s3[MAXN];int main(){ scanf("%s%s", s1, s2); int len = strlen(s1); sort(s1, s1+len); sort(s2, s2+len, greater<char>()); s3[len] = '\0'; int p1l=0, p1r=(len+1)/2-1, p2l=0, p2r=len/2-1, p3l=0, p3r=len-1; for(int i=0; i<len; ++i) { if(i%2==0) { if(s2[p2l] <= s1[p1l]) s3[p3r--] = s1[p1r--]; else s3[p3l++] = s1[p1l++]; } else { if(s1[p1l] >= s2[p2l]) s3[p3r--] = s2[p2r--]; else s3[p3l++] = s2[p2l++]; } } printf("%s\n", s3); return 0;}
阅读全文
0 0
- Codeforces Round #414 C. Naming Company 贪心
- 【Codeforces Round #414 C Naming Company】
- Codeforces 794C Naming Company 贪心
- Codeforces 794 C. Naming Company (贪心)
- codeforces C. Naming Company 贪心+博弈
- codeforces 794C Naming Company(贪心)
- C. Naming Company 贪心
- C. Naming Company 贪心
- Codeforces 794C. Naming Company
- codeforces 794C C. Naming Company
- C. Naming Company
- C. Naming Company 几何
- C. Naming Company
- Codeforces Round #321 (Div. 2) 580B Kefa and Company(贪心 + 二分)
- codeforces Naming Company 很思维题最优想法
- Codeforces Round #253 DIV1 C 贪心
- Codeforces Round #228 (Div. 1) C 贪心
- Codeforces Round #274(Div2) C. Exams 贪心
- 0025_Reverse Nodes in k-Group
- cmake: 使用jom实现msvc工程并发编译提高速度(-j)
- Activity启动流程、Window创建流程
- Link11战术数据链基础知识
- POJ 1066 Treasure Hunt(线段相交判断)
- Codeforces Round #414 C. Naming Company 贪心
- LLDB调试
- 简单易懂的github使用教程
- Window显示流程
- 框架和原生
- mysql基本语句
- java 内存机制详解 (new 操作的执行原理)
- Spark入门(2)——生态系统
- 端口的状态详解