Codeforces 1012D AB-Strings 贪心】的更多相关文章

codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x)+a.lr+b.rl,遍历完所有的点,问你最后的花费是多少 思路:每次选一个点的时候,在当前确定的每个点比较一下,选最短的距离. 为什么可以贪心?应为答案唯一,那么路径必定是唯一的,每个点所在的位置也一定是最短的. #include <bits/stdc++.h> using namespace…
CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <set> #include <map…
C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves simple strings! A string t is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add a…
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1012D.html 题目传送门 - CF1012D 题意 给定字符串 $s,t$ ,其中只包含小写字母 $a$ 和 $b$ ,而且 $a$ 和 $b$ 至少在任意一个字符串中各出现一次. 现在允许你执行一种操作:交换 $a$ 的一段前缀和 $b$ 的一段前缀.例如 $s$ 的前缀是取 $s$ 的前 $i$ 个字母,$0\leq i\leq |s|$ . 问至少执行多少次操作,并输出方案. $|s|,|t|…
题目链接: http://codeforces.com/contest/665/problem/C 题意: 改变最少的字符,使得最终序列无相同的连续的字符. 分析: 对每一个与前一个字符相同的字符,枚举满足条件的字符进行替换. 代码: #include<iostream> using namespace std; int main (void) { string s;cin>>s; int n = s.length(); for(int i = 1; i < n; i++){…
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbi…
题目链接: B. Passwords time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vanya is managed to enter his favourite site Codehorses. Vanya uses n distinct passwords for sites at all, however he can…
题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车中有凳子,那么这辆购物车中最便宜的那个物品的价格能减少50%,问你如何放这些物品才能使总价钱最少. 思路: 简单贪心,判断凳子数量是否大于等于k行. #include <bits/stdc++.h> using namespace std; typedef long long LL; typede…
Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at al…
Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopping. She will walk through a mall along a straight street, where N individual shops (numbered from 1 to N) are aligned at regular intervals. Each shop…