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. Maven教程--02设置Maven本地仓库|查看Maven中央仓库

    一:设置Maven本地仓库 Maven默认仓库的路径:~\.m2\repository,~表示我的个人文档:例如:C:\Users\Edward\.m2\repository:如下图: Maven的配 ...

  2. “吃神么,买神么”的第一个Sprint计划(第六天)

    “吃神么,买神么”项目Sprint计划 ——5.26  星期二(第六天)立会内容与进度 摘要:logo最终出来了,,背景也出来了,可以开始将完成的部分放到同一个文件中,决定剩下的时间把昨晚的部分贴上去 ...

  3. 第二次 作业——APP案例分析

    APP案例分析 产品 网易云课堂 选择理由 网易云课堂是从大一就开始使用的一款学习软件,有海量的学习资源,很适合学生课余时间的自主学习 调研,评测 上手体验 第一次打开网易云课堂app的时候,进入的是 ...

  4. 014 C语言文法定义与C程序的推导过程

  5. paperOne基于java web的简易四则运算出题网站

    项目成员:张金生     张政 需求概要 1.运算数均为正整数 2.包含的运算符有+,-,*,/ 3.除法运算结果为整除运算 4.批量生成题目并判题 核心功能分析 1.题目生成——java后端 题目生 ...

  6. foo()与@foo()的区别

    1.@foo() 是错误控制输出,foo()是正常调用输出. 2.@符号在PHP 中可以忽略错误报告,对于表达式有提示错误的,但有不影响语句执行的,可以在表达式之前加@. 3.可以把@符号放在变量.函 ...

  7. Longest Increasing Subsequence的两种解法

    问题描述: 给出一个未排序队列nums,如[10, 9, 2, 5, 3, 7, 101, 18].找出其中最长的增长序列,但不是连续增长序列,如[2, 3, 7, 101]就是对应的最长增长序列LI ...

  8. DAY2-Flask项目

    回顾: 1.安装pipenv虚拟运行环境,隔离项目 (启动:pipenv shell) 2.安装flask(pipenv install shell),查看项目依赖(pipenv graph) 3.查 ...

  9. P2144 [FJOI2007]轮状病毒

    题目描述 轮状病毒有很多变种.许多轮状病毒都是由一个轮状基产生.一个n轮状基由圆环上n个不同的基原子和圆心的一个核原子构成.2个原子之间的边表示这2个原子之间的信息通道,如图1. n轮状病毒的产生规律 ...

  10. 【比赛】NOIP2017 奶酪

    开始看到题以为是计算几何,后面发现不是,然后秒掉了. 可能写SPFA写多了,别人都是并查集做的,我用的是SPFA. 不过无所谓,我们把题目中的下底面和上表面看成两个点,那么就是求这两个点的连通性,如果 ...