【题目链接】: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的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 761A】Dasha and Stairs

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  4. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  5. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  6. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  7. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  8. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  9. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

随机推荐

  1. 【XSY2968】线性代数

    题目来源:noi2018模拟测试赛(二十二) 毒瘤板题+提答场……真tm爽 提答求最大团,各路神仙退火神仙随机化八仙过海 题意: 题解: 支持双端插入的回文自动机板题 代码: #include< ...

  2. .get(),eq()的区别

    .get(),eq()的区别 eq:返回是一个jquery对象作用是将匹配的元素集合缩减为一个元素.这个元素在匹配元素集合中的位置变为0,而集合长度变成1. get:是一个html对象数组作用是取得其 ...

  3. django开发微信公众平台遇到的问题记录

    在pythonanywhere.com上使用django开发微信公众平台应用,结果用户发送的信息,微信服务器一次也没有成功转发到pythonanywhere上来,但是用接口测试工具调试却发现是正常的, ...

  4. jquery-layer.closeAll不执行的错觉

    在使用ajax.form提交的时候,弹出了layer插件的页面,于是我想使用layer插件提供的layer.closeAll()方法讲这个弹出的页面关闭,但是尝试了很久不行,到底是为什么呢? 过了一段 ...

  5. ASP.NET-后台cookie与前台JQUERY解析cookie

    在controller中给cookie赋值 HttpCookie cookie =newHttpCookie("pageInfo"); cookie["page_inde ...

  6. jQuery fadeOut无效

    $(this).fadeOut("fast"), var nowele = $(this); nowele.fadeOut("fast")

  7. POJ3684 Physics Experiment 【物理】

    Physics Experiment Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1031   Accepted: 365 ...

  8. HDOJ 1753 大明A+B

    JAVA大数.... 大明A+B Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. 【万里征程——Windows App开发】控件大集合2

    以下再来看看一些前面还没有讲过的控件,只是控件太多以至于无法所有列出来,大家仅仅好举一反三啦. Button 前面最经常使用的控件就是Button啦,Button另一个有意思的属性呢.当把鼠标指针放在 ...

  10. Light OJ 1317 Throwing Balls into the Baskets 概率DP

    n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值 依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[ ...