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 ...
随机推荐
- 移动对meta的定义
以下是meta每个属性详解 尤其要注意的是content里多个属性的设置一定要用分号+空格来隔开,如果不规范将不会起作用. 一.<meta http-equiv="Content-Ty ...
- Oracle 课程九之绑定变量
课程目标 完成本课程的学习后,您应该能够: •变量绑定的目的 •父子游标 •游标共享 •绑定窥探 •SQL语句处理流程 •硬解析.软解析.软软解析 •变量绑定的应用场景 1.游标 游标可以理解为S ...
- IOS AFNetworking简介及使用
转:http://www.it165.net/pro/html/201405/13099.html 一AFNetworking简介AFNetworking是一个在IOS开发中使用非常多网络开源库,适用 ...
- delegate 为什么用 weak属性
weak指针主要用于“父-子”关系,父亲拥有一个儿子的strong指针,因此是儿子的所有者:但是为了阻止所有权回环,儿子需要使用weak指针指向父亲:你的viewcontroller通过strong指 ...
- CSS、CSS2和CSS3选择器总结(全部选择器种类及其优先级)
选择器种类罗列: 1.基础的选择器 选择器 含义 示例 * 通用元素选择器,匹配任何元素 * { margin:0; padding:0; } E 标签选择器,匹配所有使用E标签的元素 p { fon ...
- ili9341 横屏驱动代码
void ili9341_Initializtion(void) { u16 i; RCC->APB2ENR|=<<; //使能PORTB时钟 GPIOB->CRH&= ...
- 线段相交 POJ 2653
// 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...
- Matlab中imshow()函数的使用
imread() 返回的图像类型是uint8类型, 这时用imshow显示图像的时候, imshow会认为输入矩阵的范围在0-255, 如果imshow的参数为double类型的,那么imshow认为 ...
- 瞬间从IT屌丝变大神——HTML规范
HTML规范包含以下内容: DTD统一用<!DOCTYPE HTML PUBLIC "_//W3C//DTD XHTML 1.0 Transitional//EN"" ...
- ACM2025
/* 查找最大元素 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...