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> # ...
随机推荐
- struts2 jsp提交对象数据要这么干
不要每个属性都 setter getter .. 这样页面很难看... 直接 把对象变成一个成员变量会比较好. Java code ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
- JAVA自学日记——Part Ⅱ
今天学习了类与对象,其中关于this关键字的用法,static静态变量与静态方法,以及引用传递需要特别注意一下. 首先是引用传递: 在本段程序中可以通过进行外部对类对象的属性赋值来更改,同时也可以通过 ...
- 三公网络监督平台APP上线,源代码出售。
- 预则立&&他山之石--团队计划、访谈优秀前辈
团队计划&访谈内容 一.团队计划 序号 任务内容 计划完成时间 主要负责人 备注 1 对接教师报课系统 决定是否重构代码 2016.10.16 陈少铭.黄家俊 阅读CourseManageme ...
- PAT 甲级 1143 Lowest Common Ancestor
https://pintia.cn/problem-sets/994805342720868352/problems/994805343727501312 The lowest common ance ...
- [官网]SQLSERVER ON linux 的最低要求 以及安装方法
快速入门:在 Red Hat 上安装 SQL Server 并创建数据库 总体说明: 适用于: SQL Server (仅限 Linux)Azure SQL 数据库Azure SQL 数据仓库并行数据 ...
- 016 Java中的动态代理
作者:nnngu GitHub:https://github.com/nnngu 博客园:http://www.cnblogs.com/nnngu 简书:https://www.jianshu.com ...
- spring接收json字符串的两种方式
一.前言 前几天遇到一个问题,前端H5调用我的springboot一个接口(post方式,@RequestParameter接收参数),传入的参数接收不到.自己测试接口时使用postman的form- ...
- Alpha 冲刺 —— 十分之四
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 协助前后端接口的开发 测试项目运行的服务器环 ...
- java关于类加载的面试题
---面试题 class SingleTon { private static SingleTon singleTon = new SingleTon(); public static int cou ...