【codeforces 46C】Hamsters and Tigers
【题目链接】:http://codeforces.com/problemset/problem/46/C
【题意】
给你一个长度为n的01串;
让你把所有的0放在一起,把所有的1放在一起;
(即0都是连续着在一起,1也是连续着在一起)
问你最少需要进行多少次交换操作;
【题解】
先算出仓鼠有多少只ch;
然后枚举每一个点i;
最后的结果必然是仓鼠都在连续的一段;
则假设在[i,i+ch-1]这一段;
算出里面有多少只狮子;
则把这些狮子移到这个区间外面去就好(把仓鼠换进来);
在所有区间里面取最小的狮子数目;
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("D:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)typedef pair<int,int> pii;
typedef pair<LL,LL> pll;const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int oo = 0x3f3f3f3f;int n,ch,len,ans=oo;
string s;int main(){//Open();Close();//scanf,puts,printf not use//init??????cin >> n;cin >> s;len = (int) s.size();rep1(i,0,(int) s.size()-1){if (s[i]=='H') ch++;}s = s+s;rep1(i,0,len-1){int ct = 0;rep1(j,i,i+ch-1)if (s[j]=='T')ct++;ans = min(ans,ct);}cout << ans << endl;return 0;
}
【codeforces 46C】Hamsters and Tigers相关推荐
- 【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)
题干: A string t is called an anagram of the string s, if it is possible to rearrange letters in t so ...
- 【CodeForces - 574B】Bear and Three Musketeers (枚举边,思维,优秀暴力)
题干: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Ri ...
- 【CodeForces - 608C】Chain Reaction (二分 或 dp ,思维)
题干: 题目大意: 题意是在一条直线上坐落着不同位置的灯塔,每一个灯塔有自己的power level,当作是射程范围.现在从最右边的灯塔开始激发,如果左边的灯塔在这个灯塔的范围之内,那么将会被毁灭.否 ...
- 「一题多解」【CodeForces 85D】Sum of Medians(线段树 / 分块)
题目链接 [CodeForces 85D]Sum of Medians 题目大意 实现一个setsetset,支持插入,删除,求∑a5k+3∑a5k+3\sum a_{5k+3}.注意,setsets ...
- 【CodeForces 997C】Sky Full of Stars(组合计数)
题目链接:[CodeForces 997C]Sky Full of Stars 官方题解:Codeforces Round #493 - Editorial 题目大意:有一个n×nn×nn\times ...
- 【codeforces 812C】Sagheer and Nubian Market
[题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...
- 【codeforces 508B】Anton and currency you all know
[题目链接]:http://codeforces.com/contest/508/problem/B [题意] 给你一个奇数; 让你交换一次数字; 使得这个数字变成偶数; 要求偶数要最大; [题解] ...
- 【codeforces 711B】Chris and Magic Square
[题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...
- 【codeforces 807C】Success Rate
[题目链接]:http://codeforces.com/contest/807/problem/C [题意] 给你4个数字 x y p q 要求让你求最小的非负整数b; 使得 (x+a)/(y+b) ...
最新文章
- vim不支持python3_彻底颓了—— Vim Python 3 接口不支持中文
- Java线程之线程池
- rsync与inotify实现数据实时同步
- 听说你想去大厂看学姐,带你看看拼多多运营面经
- 【模板】可持久化线段树 1(主席树)
- 【PAT】A1060 Are They Equal *
- python计算程序运行时间
- 2017.8.16 喵星球上的点名 思考记录
- PyChram使用技巧
- 如何使用自动化与分析工具库创建 Excel 直方图
- 为你解惑之WPF经典9问详解
- PostGreSQL安装压缩包格式
- TZT3826E静态信号测试分析系统
- iOS 将状态栏设置成白色
- dubbo 监控中心配置
- 物联网应用技术竞赛 ——数据库添加新用户映射
- linux 修复文件fsck,使用fsck检查并修复文件系统[Linux] | MOS86
- thinkphp6限制接口访问频次
- 互联网行业应届待遇十一档2014
- 微信小程序获取用户IP地址,HTTPS接口
热门文章
- Gen8服务器系统安装,Gen8安装Esxi系统教程
- c语言declared void,c语言求助 [Error] variable or field 'RRR2' declared void
- Unity Rigidbody碰撞检测的三种模式Collision Detection
- 如何创建一个私有的Docker仓库
- oracle 11g ora31626,重建DBMS_STATS解决ORA-31626 ORA-21633以及ORA-04063 ORA-06508 错误
- Windows操作系统用注册表删除启动项
- 2021江苏省c语言二级考试时间,2019年9月江苏二级计算机考试时间公布
- mysql附录建表_用CREATE TABLE 语句创建数据表
- java byte追加_byte数组追加 java
- 为什么要人造元素_人造元素