TC SRM 663 div2 A ChessFloor 暴力
ChessFloor
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
TC
Description
Samantha is renovating a square room. The floor of the room is an N times N grid of unit square tiles. Each tile has some color. You are given the current colors of all tiles in a vector <string> floor with N elements, each containing N characters. Each character represents one tile. Identical characters represent tiles of the same color.
Samantha wants to be able to play chess or checkers on the floor. Hence, she wants to change the entire floor into a checkerboard pattern. A checkerboard pattern has two properties:
there are exactly two distinct colors of tiles
no two tiles of the same color share a common side
For example, this is a checkerboard pattern:
afa
faf
afa
This is not a checkerboard pattern because there are more than two distinct colors:
aba
bcb
aba
This is not a checkerboard pattern because there are two tiles that share a side and have the same color:
aaa
bab
aba
Samantha wants to change her floor into a checkerboard pattern by changing the colors of as few tiles as possible. Compute and return the number of tiles she needs to change.
Input
-
N will be between 2 and 20, inclusive.
-
floor will contain exactly N elements.
-
Each element of floor will consist of exactly N characters.
-
Each character in floor will be a lowercase English letter ('a'-'z').
Output
Class:
ChessFloor
Method:
minimumChanges
Parameters:
vector <string>
Returns:
int
Method signature:
int minimumChanges(vector <string> floor)
(be sure your method is public)
Sample Input
{"wbwbwbwb",
"bwbwbwbw",
"wbwbwbwb",
"bwbwbwbw",
"wbwbwbwb",
"bwbwbwbw",
"wbwbwbwb",
"bwbwbwbw"}
Sample Output
0
HINT
题意
给你一个n*n的棋盘,让你修改最少的字母,让这个棋盘形成相间的模样
题解:
暴力!不要想多了,就直接暴力!
代码
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std; class ChessFloor{
public:
int minimumChanges(vector <string> floor){
int ans=;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(i==j)
continue;
int ans1=;
for(int ii=;ii<floor.size();ii++)
{
for(int jj=;jj<floor.size();jj++)
{
if((ii+jj)%==)
{
if(floor[ii][jj]!=char(i+'a'))
ans1++;
}
else
{
if(floor[ii][jj]!=char(j+'a'))
ans1++;
} }
}
ans=min(ans,ans1);
}
}
return ans;
}
};
TC SRM 663 div2 A ChessFloor 暴力的更多相关文章
- TC SRM 663 div2 B AABB 逆推
AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...
- TC SRM 665 DIV2 A LuckyXor 暴力
LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...
- TC SRM 665 DIV2 B LuckyCycle 暴力
LuckyCycleTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.ac ...
- TC SRM 664 div2 A BearCheats 暴力
BearCheats Problem Statement Limak is an old brown bear. Because of his bad eyesight he sometime ...
- TC SRM 607 DIV2
求拼接完成后的字符串包含的子回文串的数目,一开始还用暴力去做,想都不用想 肯定超时了. 复习了一下求最长子回文串的算法,发现可以类似解决. 给相邻字符之间添加一个'@'字符,这样所有的回文串都是奇数长 ...
- TC SRM 593 DIV2 1000
很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 591 DIV2 1000
很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...
- tc srm 636 div2 500
100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 664 div2 B BearPlaysDiv2 bfs
BearPlaysDiv2 Problem Statement Limak is a little bear who loves to play. Today he is playing by ...
随机推荐
- 【DFS】NYOJ-82 迷宫寻宝(一)-条件迷宫问题
[题目链接:NYOJ-82] #include<iostream> #include<cstring> using namespace std; struct node{ in ...
- Oracle RAC OCR 的备份与恢复
Oracle Clusterware把整个集群的配置信息放在共享存储上,这些信息包括了集群节点的列表.集群数据库实例到节点的映射以及CRS应用程序资源信息.也即是存放在ocr 磁盘(或者ocfs文件) ...
- [转]Android调用so文件(C代码库)方法详解
一.为什么调用c的dll要用源码编译成so库 Android系统是基于linux内核的移动终端系统,而dll是在windows环境下生成和调用的c库,所以不可以直接为android系统调用. 二.安装 ...
- [转] C# 中的static静态变量
logitechyan原文关于C#中static静态变量 C#静态变量使用static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明的变量称做非静态变量,在对象被 ...
- [Everyday Mathematics]20150105
设 $f\in C^1(a,b)$ 适合 $$\bex \lim_{x\to a^+}f(x)=+\infty,\quad \lim_{x\to b^-}f(x)=-\infty, \eex$$ 并且 ...
- POJ 3744 Scout YYF I (概率dp+矩阵快速幂)
题意: 一条路上,给出n地雷的位置,人起始位置在1,向前走一步的概率p,走两步的概率1-p,踩到地雷就死了,求安全通过这条路的概率. 分析: 如果不考虑地雷的情况,dp[i],表示到达i位置的概率,d ...
- SQL你必须知道的-函数及类型转换
use MySchoolTwo --ISNULL(expression,value) :如果 expression不为空则返回 expression ,否则返回 value. select ...
- CodeForce---Educational Codeforces Round 3 Load Balancing 正题
看到这题是我的想法就是肯定跟平均值有关但是接下来就不知道怎么做了 看完大神的正解数之后,原来发现是这么简单,但是就是不知道为啥一定是平均值和平均值加1,而不是平均值和平均值减1: 好啦下面就贴出大神的 ...
- 【原】Kryo序列化篇
Kryo是一个快速有效的对象图序列化Java库.它的目标是快速.高效.易使用.该项目适用于对象持久化到文件或数据库中或通过网络传输.Kryo还可以自动实现深浅的拷贝/克隆. 就是直接复制一个对象对象到 ...
- CORBA
公共对象请求代理体系结构(Common Object Request Broker Architecture)