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的更多相关文章

  1. 2018.07.20 atcoder Largest Smallest Cyclic Shift(贪心)

    传送门 题意:给你x个a,y个b,z个c,显然这些字符可以拼成若干字符串,然后求这些字符串中最小表示法表示出来的最大的那一个. 解法:贪心思想,用multiset维护现在拼成的字串,每次取一个最小的和 ...

  2. [Atcoder Code Festival 2017 Qual B Problem F]Largest Smallest Cyclic Shift

    题目大意:给你\(A\)个a,\(B\)个b,\(C\)个c,要你构造一个字符串,使它的最小循环表示法最大.求这个表示法.解题思路:不知道怎么证,但把a.b.c当做单独的字符串扔进容器,每次把字典序最 ...

  3. 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 ...

  4. codeforces 709C C. Letters Cyclic Shift(贪心)

    题目链接: C. Letters Cyclic Shift 题意: 现在一串小写的英文字符,每个字符可以变成它前边的字符即b-a,c-a,a-z这样,选一个字串变换,使得得到的字符串字典序最小; 思路 ...

  5. Codeforces 708A Letters Cyclic Shift

    A. Letters Cyclic Shift time limit per test:1 second memory limit per test:256 megabytes input:stand ...

  6. 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 ...

  7. CF708A Letters Cyclic Shift 模拟

    You are given a non-empty string s consisting of lowercase English letters. You have to pick exactly ...

  8. Codeforces Problem 708A Letters Cyclic Shift

     题目链接: http://codeforces.com/problemset/problem/708/A 题目大意: 从字符串s中挑选出一个子串(非空),将该子串中的每个字母均替换成前一个字母,如' ...

  9. CodeForces 709C Letters Cyclic Shift (水题)

    题意:给定一个字符串,让你把它的一个子串字符都减1,使得总字符串字典序最小. 析:由于这个题是必须要有一个字串,所以你就要注意这个只有一个字符a的情况,其他的就从开始减 1,如果碰到a了就不减了,如果 ...

随机推荐

  1. poj 1298 The Hardest Problem Ever

    题目链接:http://poj.org/problem?id=1298 题目大意:按照所给的顺序要求将输入的字符串进行排列. #include <iostream> #include &l ...

  2. DesignPattern

    目录

  3. LeetCode 19 Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  4. python实战===老司机奇技淫巧系列之字符转换成图片

    先放两张效果图:

  5. 【学习笔记】动态树Link-Cut-Tree

    这是两个月前写的,看能不能搬运过来…… 动态树是一类维护森林连通性的问题(已纠正,感谢ZQC巨佬),目前最(wo)常(zhi)见(hui)的动态树就是LCT(Link-Cut-Tree),然而LCT似 ...

  6. nodejs面试题

    1.为什么用Nodejs,它有哪些缺点? 事件驱动,通过闭包很容易实现客户端的生命活期. 不用担心多线程,锁,并行计算的问题 V8引擎速度非常快 对于游戏来说,写一遍游戏逻辑代码,前端后端通用 当然N ...

  7. 我的第一个web开发框架

    怎么才能成为一名架构师?需要具备哪些条件? 作为一名码农我迫切希望自己成为一个比较合格的web架构师,昨晚心血来潮小弟花了4个小时的时间整了个简易的web开发框架,本着开源的精神做个分享,希望和更多的 ...

  8. CSS Modules入门及React中实践(内附webpack4配置)

    本篇文章以整理为主,自己进行了部分修改,如有侵权,请告知 CSS Modules介绍 CSS Modules是什么东西呢?首先,让我们从官方文档入手:GitHub – css-modules/css- ...

  9. vue分页tbale小荔枝

    首先,动态加载数据 <table class="table table-bordered table-condensed no_margin_bottom jyjg_tab" ...

  10. LoadRunner中常用函数参考手册

    基础篇1:LoadRunner中常用函数参考手册 常用函数列表 web_url web_submmit_form VS web_submmit_data VS web_custom_request w ...