CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
https://www.codechef.com/DEC17/problems/GIT01
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- #define N 101
- char s[N];
- int main()
- {
- int T;
- scanf("%d",&T);
- int n,m;
- int OddG,OddR,EvenG,EvenR;
- int ans;
- while(T--)
- {
- OddG=OddR=EvenG=EvenR=;
- scanf("%d%d",&n,&m);
- for(int i=;i<=n;++i)
- {
- scanf("%s",s+);
- for(int j=;j<=m;++j)
- {
- if(s[j]=='G')
- {
- if((i+j)&) OddG++;
- else EvenG++;
- }
- else
- {
- if((i+j)&) OddR++;
- else EvenR++;
- }
- }
- }
- ans=*OddR+*EvenG;
- ans=min(ans,*OddG+*EvenR);
- printf("%d\n",ans);
- }
- }
All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian andVietnamese as well.
Chef’s girlfriend's birthday is near, so he wants to surprise her by making a special cake for her. Chef knows that his girlfriend likes cherries on the cake, so he puts cherries on the top of the cake, but he was not satisfied. Therefore, he decided to replace some of the cherries to make a beautiful pattern. However, Chef has a lot of other work to do so he decided to ask for your help.
The cherries are of two colors red and green. Now Chef wants the cherries to be placed in such a way that each cherry of one color must be adjacent to only cherries of the other color, two cherries are adjacent if they share a side. Now Chef has asked for your help in making that pattern on the cake.
You can replace any cherry of given color with the other color. But there is a cost for each replacement: if you replace a red cherry with a green one, the cost is 5 units and if you replace a green cherry with a red one, the cost is 3 units.
Help your friend Chef by making the cake special with minimum cost.
Input
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains two space-separated integers N and M, where N × M are the dimensions of the cake.
- Each of the next N lines contains a string of length M.
Output
For each test case, output the minimum cost required to make the cake special.
Constraints
- 1 ≤ T ≤ 100
- 1 ≤ N, M ≤ 100
- each string consists only of letters 'R' and 'G' denoting red and green cherries respectively
Example
- Input:
- 2
- 4 5
- RGRGR
- GRGRG
- RGRGR
- GRGRG
- 2 3
- RRG
- GGR
- Output:
- 0
- 8
CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake的更多相关文章
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays
https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds
https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out
https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...
随机推荐
- 校园跳蚤市场-Sprint计划(第二阶段)
- golang type
参考链接 https://blog.csdn.net/tzs919/article/details/53571632 type是golang中非常重要的关键字,常见的就是定义结构体,但是其功能远不止是 ...
- 团队作业5-Alpha版本测试报告(彼岸芳华队)
请根据团队项目中软件的需求文档.功能说明.系统设计和测试计划,写出软件的测试过程和测试结果,并回答下述问题. 一.在测试过程中总共发现了多少Bug?每个类别的Bug分别为多少个?(10分) 在测试过程 ...
- fir.im的高级统计功能
fir.im的高级统计功能,可以根据渠道和活动名称,统计不同渠道和活动带来的下载量.操作步骤如下: 第一步:生成统计链接 点击高级统计,进入统计详情页,然后点击生成统计链接: 设置统计链接的应用版本. ...
- Beta阶段——第二篇 Scrum 冲刺博客
i. 提供当天站立式会议照片一张: ii. 每个人的工作 (有work item 的ID) (1) 昨天已完成的工作: 账单收支分明,剩余舍费关联成功 (2) 今天计划完成的工作: 账单删除功能,排序 ...
- 四人小组:vip会员管理系统
需求概述: 针对各类商铺百花齐放的现状,越来越多的商家考虑用各种方式招揽顾客,会员制度一向是吸引回头客的不二法宝.用户持有会员卡能够迅捷的购物,享有普通顾客更多的优惠或回馈.乃至新品推送.积分等一系列 ...
- linux 无交互生成ssh rsa免秘证书
[root@xxx tmp]# man ssh-keygen NAME ssh-keygen - authentication key generation, management and conve ...
- dstat 监控时,无颜色显示
linux:Centos 6.6 dstat:0.7.0 注意,有这个提醒:Color support is disabled, python-curses is not installed good ...
- [转帖]InfiniBand技术和协议架构分析
InfiniBand技术和协议架构分析 2017年06月06日 20:54:16 Hardy晗狄 阅读数:15207 标签: 云计算存储Infiniband 更多 个人分类: 存储云计算 版权声明 ...
- docker weave安装
1.升级内核到3.10.0以上,安装iproute22.安装 0.80版本:#wget -O /usr/local/bin/weave https://raw.githubusercontent.co ...