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 ...
随机推荐
- Java基础——I/O
文本I/O与二进制I/O 在计算机中所有的文件都是以二进制的形式来存储的,所以本质上所有的文件都是二进制文件. 文本I/O建立在二进制I/O的基础之上,它能提供字符层次的编码和解码的抽象,在写入一个字 ...
- 【JS】<c:foreach>用法
<c:foreach>类似于for和foreach循环 以下是我目前见过的用法: 1.循环遍历,输出所有的元素. <c:foreach items="${list}&q ...
- 常见的js函数
改变元素的样式 var changeStyle = function(elem,name,value){ elem.style[name] = value; } 空位补零 fu ...
- 反转链表 --剑指offer
题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反正后链表的头结点. #include<stdio.h> #include<malloc.h> typedef str ...
- Delphi 利用TComm组件 Spcomm 实现串行通信
Delphi 利用TComm组件 Spcomm 实现串行通信 摘要:利用Delphi开发工业控制系统软件成为越来越多的开发人员的选择,而串口通信是这个过程中必须解决的问题之一.本文在对几种常用串口通信 ...
- ASP.net MVC基础
简单了解了下MVC的基本开发步骤后,又对MVC的语法和模版详细看看了,小小总结下 对mvc开发,首先是要对布局有个基本的认识.Razor引擎使页面元素更加清晰 简单认识下 可以加载css和js等文件, ...
- SeaJS学习笔记(一) ./ 和 ../ 区别
最近要去实习,公司里使用sea.js进行模块化开发 具体下载安装就不多说了,请参见SeaJS官网 <!DOCTYPE html> <html> <head> < ...
- 线性模型(1):Perceptron Learning Algorithm (PLA)
此笔记源于台湾大学林轩田老师<机器学习基石><机器学习技法> (一) PLA算法是基本的binary Classification算法. 一个基本的问题是,对于银行,假设我知道 ...
- 线段相交 POJ 2653
// 线段相交 POJ 2653 // 思路:数据比较水,据说n^2也可以过 // 我是每次枚举线段,和最上面的线段比较 // O(n*m) // #include <bits/stdc++.h ...
- 修改MongoDb的 DB 和 Log 存储路径 (Windows)-摘自网络
Create a file called mongod.cfg in MongoDB folder if you dont have it. In my case: C:\Users\ivanbtru ...