Largest Smallest Cyclic Shift
Largest Smallest Cyclic Shift
题目来源:
Atcoder Code Festival 2017 Qual B Problem F
题目大意:
有\(X\)个字符'a'
,\(Y\)个字符'b'
,\(Z\)个字符'c'
。用它们组成字符串,求最小表示的最大值。
思路:
贪心。首先将所有由单个字符构成的字符串插入到一个multiset<string>
中,每次选取最小串\(s\)和最大串\(t\)。此时最小表示一定是由\(s\)开头的,而将\(t\)接在\(s\)后面可以让最小表示尽可能大,因此可以将\(s\)和\(t\)从multiset
中删去,插入\(s+t\),最后仅剩一个串时将其输出即可。
源代码:
#include<set>
#include<cstdio>
#include<cctype>
#include<string>
inline int getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int x=ch^'0';
while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
return x;
}
int main() {
std::multiset<std::string> set;
for(register int i=getint();i;i--) set.insert("a");
for(register int i=getint();i;i--) set.insert("b");
for(register int i=getint();i;i--) set.insert("c");
while(set.size()>1) {
std::string s=*set.begin(),t=*set.rbegin();
set.erase(set.lower_bound(s));
set.erase(set.lower_bound(t));
set.insert(s+t);
}
printf("%s\n",(*set.begin()).c_str());
return 0;
}
Largest Smallest Cyclic Shift的更多相关文章
- 2018.07.20 atcoder Largest Smallest Cyclic Shift(贪心)
传送门 题意:给你x个a,y个b,z个c,显然这些字符可以拼成若干字符串,然后求这些字符串中最小表示法表示出来的最大的那一个. 解法:贪心思想,用multiset维护现在拼成的字串,每次取一个最小的和 ...
- [Atcoder Code Festival 2017 Qual B Problem F]Largest Smallest Cyclic Shift
题目大意:给你\(A\)个a,\(B\)个b,\(C\)个c,要你构造一个字符串,使它的最小循环表示法最大.求这个表示法.解题思路:不知道怎么证,但把a.b.c当做单独的字符串扔进容器,每次把字典序最 ...
- Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题
A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...
- codeforces 709C C. Letters Cyclic Shift(贪心)
题目链接: C. Letters Cyclic Shift 题意: 现在一串小写的英文字符,每个字符可以变成它前边的字符即b-a,c-a,a-z这样,选一个字串变换,使得得到的字符串字典序最小; 思路 ...
- Codeforces 708A Letters Cyclic Shift
A. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...
- AIM Tech Round 3 (Div. 1) A. Letters Cyclic Shift 贪心
A. Letters Cyclic Shift 题目连接: http://www.codeforces.com/contest/708/problem/A Description You are gi ...
- CF708A Letters Cyclic Shift 模拟
You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly ...
- Codeforces Problem 708A Letters Cyclic Shift
题目链接: http://codeforces.com/problemset/problem/708/A 题目大意: 从字符串s中挑选出一个子串(非空),将该子串中的每个字母均替换成前一个字母,如' ...
- CodeForces 709C Letters Cyclic Shift (水题)
题意:给定一个字符串,让你把它的一个子串字符都减1,使得总字符串字典序最小. 析:由于这个题是必须要有一个字串,所以你就要注意这个只有一个字符a的情况,其他的就从开始减 1,如果碰到a了就不减了,如果 ...
随机推荐
- Java 关于微信公众号支付总结附代码
很多朋友第一次做微信支付的时候都有蒙,但当你完整的做一次就会发现其实并没有那么难 业务流程和应用场景官网有详细的说明:https://pay.weixin.qq.com/wiki/doc/api/js ...
- [Leetcode Week14]Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/pr ...
- 安全测试===sqlmap
本文转自:https://www.secpulse.com/archives/4213.html 鉴于很多新手对sqlmap的用法不是很熟悉 很多常用sqlmap的也不一定完全会用sqlmap 特 ...
- python基础=== itertools介绍(转载)
原文链接:http://python.jobbole.com/85321/ Python提供了一个非常棒的模块用于创建自定义的迭代器,这个模块就是 itertools.itertools 提供的工具相 ...
- TensorFlow计算模型—计算图
TensorFlow是一个通过计算图的形式来表述计算的编程系统.其中的Tnesor,代表它的数据结构,而Flow代表它的计算模型.TensorFlow中的每一个计算都是计算图上的一个节点,而节点之间的 ...
- ASP.NET 163 smtp服务器响应为:User has no permission
1.问题引出 今天在asp.net程序中,利用System.Net.Mail.MailMessage类和网易163免费邮箱服务器发送邮件时出现了如下问题. 2.解决方案 原因很简单,我们在asp.ne ...
- 使用Webpack搭建Vue项目
前提: 1. 借助Node.js环境里的npm来安装, 2. 设置好npm镜像, (比如淘宝的npm镜像:输入 引用 npm install -g cnpm –registry=https://r ...
- Windows下修改oracle实例不随服务自动启动
设置Oracle Administration Assistant for Windows 开始->所有程序->Oracle - OraDb10g_home1->配置和移植工具-&g ...
- Two Sum ——经典的哈希表的题
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- 前端读者 | CSS三角形和饼图
@羯瑞 三角形 .triangle{width:0;height:0;border-width:50px;border-style:solid;border-color:red blue green ...