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 chineseRussian 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的更多相关文章

  1. 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] 表示第 ...

  2. 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 ...

  3. CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

    https://www.codechef.com/DEC17/problems/VK18 #include<cstdio> #include<iostream> #includ ...

  4. CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out

    https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using ...

  5. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  6. 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的数 维护 ...

  7. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

  8. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  9. 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> # ...

随机推荐

  1. 关于mybatis的思考(2)——mybatis映射文件的深入理解

    1.配置文件 mybatis进行持久化操作是以SqlSessionFactory对象为基础的,这个对象是整个数据库映射关系经过编译后的内存镜像. InputStream inputStream = R ...

  2. 四人小组:vip会员管理系统

    需求概述: 针对各类商铺百花齐放的现状,越来越多的商家考虑用各种方式招揽顾客,会员制度一向是吸引回头客的不二法宝.用户持有会员卡能够迅捷的购物,享有普通顾客更多的优惠或回馈.乃至新品推送.积分等一系列 ...

  3. Linux限制cpu睿频&限制频率

    .关闭睿频 > /sys/devices/system/cpu/intel_pstate/no_turbo .限制CPU最大频率到50% " | sudo tee /sys/devic ...

  4. vue 组件 模板input双向数据数据

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>T ...

  5. SpringBoot(六)_AOP统一处理请求

    什么是AOP AOP 是一种编程范式,与编程语言无关: 将通用逻辑从业务逻辑中分离出来(假如你的业务是一条线,我们不在业务线上写一行代码就能完成附加任务!我们会把代码写在其他的地方): 具体实现 (1 ...

  6. MySQL复制 -- binlog(2)

    MySQL复制是使用最为广泛的一套组建,上一节已经简单说了一下复制的一些用途和复制的原理,知道了这些我们能够快速的搭建起复制的平台,但是仅知道这些还是不够的,很多时候并不是一帆风顺的,总会有那么一小段 ...

  7. BZOJ5294 BJOI2018二进制(线段树)

    二进制数能被3整除相当于奇数.偶数位上1的个数模3同余.那么如果有偶数个1,一定存在重排方案使其合法:否则则要求至少有两个0且至少有3个1,这样可以给奇数位单独安排3个1. 考虑线段树维护区间内的一堆 ...

  8. P1503 鬼子进村

    题目背景 小卡正在新家的客厅中看电视.电视里正在播放放了千八百次依旧重播的<亮剑>,剧中李云龙带领的独立团在一个县城遇到了一个鬼子小队,于是独立团与鬼子展开游击战. 题目描述 描述 县城里 ...

  9. HDU 6184 Counting Stars

    Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful!S ...

  10. 【转】LINQ多表关联关联条件

    转:http://www.dingcankong.com/linq%E4%B8%A4%E8%A1%A8%E8%81%94%E5%90%88%E6%9F%A5%E8%AF%A2/ 答案如下: var m ...