博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
阅读量:4878 次
发布时间:2019-06-11

本文共 2515 字,大约阅读时间需要 8 分钟。

 

#include
#include
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=0; scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) { scanf("%s",s+1); for(int j=1;j<=m;++j) { if(s[j]=='G') { if((i+j)&1) OddG++; else EvenG++; } else { if((i+j)&1) OddR++; else EvenR++; } } } ans=5*OddR+3*EvenG; ans=min(ans,3*OddG+5*EvenR); printf("%d\n",ans); }}

 

All submissions for this problem are available.

Read problems statements in ,  and 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:24 5RGRGRGRGRGRGRGRGRGRG2 3RRGGGROutput:08

转载于:https://www.cnblogs.com/TheRoadToTheGold/p/8059959.html

你可能感兴趣的文章
HDU 2039 三角形
查看>>
Softmax实现 fashion.mnist 分类
查看>>
统计学习-朴素贝叶斯法
查看>>
学习进度17
查看>>
编译原理——算符优先分析文法(附源代码)
查看>>
jboss的启动过程
查看>>
渲染部分
查看>>
力扣——所有可能的路径
查看>>
关于VS项目平台的x86,x64,Any CPU以及Debug和Release的区别
查看>>
解密module_init幕后的故事
查看>>
9个移动网站优化的最佳实践
查看>>
李昌镐:苍老的青春(转载) 韩国围棋职业棋手
查看>>
JPA 使用报Named query not found错误
查看>>
FTP命令使用详解
查看>>
walmart weekly sales
查看>>
面试题07_用两个栈实现队列——剑指offer系列
查看>>
cocos2d-x3.2中加入Android手机震动
查看>>
css3处理sprite背景图压缩来解决H5网页在手机浏览器下图标模糊的问题
查看>>
温故而知新练习3
查看>>
【转】iOS应用崩溃日志分析
查看>>