Codeforces 719B Anatoly and Cockroaches】的更多相关文章

B. Anatoly and Cockroaches time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there tog…
题目链接:http://codeforces.com/problemset/problem/719/B 题目大意: 有一队蟑螂用字符串表示,有黑色 ‘b’ 和红色 'r' 两种颜色,你想使这队蟑螂颜色分布是交叉的,你有两种做法: 一次调整任意两个交换位置,或者一次给一个蟑螂染色 问,最少操作多少次可以使得蟑螂的颜色分布是交叉的. 解题思路: 刚看完题,就想到用一个字符接受第一个蟑螂的颜色[下标从0开始],for 如果 是奇数则 应该与第一蟑螂的颜色不同,如果相同 ++c1,如果是偶数,就应该与第…
题目大意:有一排蟑螂,只有r和b两种颜色,你可以交换任意两只蟑螂的位置,或涂改一个蟑螂的颜色,使其变成r和b交互排列的形式.问做少的操作次数. 题目思路:更改后的队列只有两种形式:长度为n以r开头:长度为n以b开头.与初始串进行比较并统计改变次数记作ans,算出必须进行的涂色操作的次数step,我们可以把交换两只不同颜色的蟑螂的位置看做进行了两次涂改操作,其次数为(ans-step). 那么得出改变为模板串的最小操作次数为:step+(ans-step)/2; #include<iostream…
题意:给定一个序列,让你用最少的操作把它变成交替的,操作有两种,任意交换两种,再就是把一种变成另一种. 析:贪心,策略是分别从br开始和rb开始然后取最优,先交换,交换是最优的,不行再变色. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <c…
B. Anatoly and Cockroaches 题目连接: http://codeforces.com/contest/719/problem/B Description Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of tw…
题目链接:http://codeforces.com/contest/719/problem/B B. Anatoly and Cockroaches time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anatoly lives in the university dorm as many other students do. A…
B. Anatoly and Cockroaches time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there tog…
Description Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room. An…
time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockro…
Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room. Anatoly just m…