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> # ...
随机推荐
- 浅谈对IT的认识!
我是一个从农村出来的学生,家里的情况和大多数的农村同学是一样的,家里算不上有钱,父母供我读书,也已经是做到仁至义尽了. 我现在选了,一个和计算机有关的专业---计算机应用技术.就是希望毕业后,可以找到 ...
- 牛客网国庆集训派对Day5 题目 2018年
链接:https://www.nowcoder.com/acm/contest/205/L来源:牛客网参考博客:https://blog.csdn.net/HTallperson/article/de ...
- 深入理解Java类加载器(3)
5.2 网络类加载器 下面将通过一个网络类加载器来说明如何通过类加载器来实现组件的动态更新.即基本的场景是:Java 字节代码(.class)文件存放在服务器上,客户端通过网络的方式获取字节代码并执行 ...
- GDI+ 支持的图片文件格式
您可以使用许多标准格式将位图储存在磁盘文件中.GDI+ 支持以下各种图片文件格式. o 位图 (BMP) 位图是 Windows 用来储存设备无关和与应用程序无关的图片的标准格式.文件头决定了指定的位 ...
- 移动web适配利器-rem
移动web适配利器-rem 前言 提到rem,大家首先会想到的是em,px,pt这类的词语,大多数人眼中这些单位是用于设置字体的大小的,没错这的确是用来设置字体大小的,但是对于rem来说它可以用来做移 ...
- 错误“AxImp.exe”已退出,代码为 -1163019603【转载及个人看法】
http://blog.csdn.net/duguduchong/article/details/17166123 最近使用vs2010 在重新生成解决方案的时候出现 “AxImp.exe”已退出, ...
- mysql中字符串类型char(n)和varchar(n)的区别
n的含义 根据网络上找到的结果(不能保证准确),在5.0.3以后版本中,n均代表字符数,而不是字节数:我用来测试的版本是5.7.20,该版本中,n表示字符数. 验证过程如下 建表 CREATE TAB ...
- UVA10047_The Monocycle
这题....有点奇葩,但是不难. 在矩形方阵里,某人可以往前走或者左拐右拐.都需要消耗一个单位时间. 问某人从一个点走向另一个点的最短时间,并且走过的路程是5的倍数. 由于n,m都小,直接f[n][m ...
- python list类型的变量相当于全局变量 可以被函数与类引用
python list类型的变量相当于全局变量 可以被函数与类引用
- MT【118】利用线面角最小解题
解:如图将正四面体放到立方体中,让AB通过$\alpha$面,让$\alpha$面绕着AB动起来.问题就转化成为EF与面$\alpha$线面角$\theta$了.EF的投影为$|EF|cos\thet ...