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

最新文章

  1. BonBon - 使用 CSS3 制作甜美的糖果按钮
  2. JVM内存区域与内存溢出异常
  3. spring mvc 通过配置xml访问控制器的三种方式
  4. 研究实验1_搭建一个精简的C语言开发环境(包含部分经典的前言)
  5. 索引 split2
  6. object to primitive in javascript
  7. Oracle 单实例 2个service的问题
  8. spring事务回滚无法捕捉
  9. Java接口,抽象类
  10. 【HDOJ】1726 God’s cutter
  11. SQL笔记 --- 数据库设计步骤(转)
  12. Open Daylight integration with OpenStack: a tutorial
  13. python学习——用dictionary实现通过地区查询邮编
  14. bootstrap-fileinput文件上传控件的亲身实践
  15. MYSQL 文件类型
  16. Memcache cpu占用过高
  17. python-pandas 高级功能(通过学习kaggle案例总结)
  18. C#DateTime好用但不常用的用法
  19. iOS边练边学--简单的数据操作(增、删、改),左滑动删除和弹窗
  20. 转一个财务方面常用到的数字金额转成汉字大写金额 php类

热门文章

  1. imooc-c++学习感悟
  2. 404 Note Found Team&#39;s First Blood
  3. Java 经典 书籍
  4. Beta阶段冲刺前的准备
  5. QT源码解析(七)Qt创建窗体的过程,作者“ tingsking18 ”(真正的创建QPushButton是在show()方法中,show()方法又调用了setVisible方法)
  6. Angular 动态组件
  7. HUAS 2017暑假第六周比赛-题解
  8. Error:Artifact &#39;xx.war exploded&#39; has invalid extension
  9. JeeSite 4.x SAAS 多租户技术设计方案
  10. Luogu 3369 我用线段树骗了一道平衡树题……