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=999999999;
        for(int i=0;i<26;i++)
        {
            for(int j=0;j<26;j++)
            {
                if(i==j)
                    continue;
                int ans1=0;
                for(int ii=0;ii<floor.size();ii++)
                {
                    for(int jj=0;jj<floor.size();jj++)
                    {
                        if((ii+jj)%2==0)
                        {
                            if(floor[ii][jj]!=char(i+‘a‘))
                                ans1++;
                        }
                        else
                        {
                            if(floor[ii][jj]!=char(j+‘a‘))
                                ans1++;
                        }

                    }
                }
                ans=min(ans,ans1);
            }
        }
        return ans;
    }
};
时间: 2024-10-12 21:35:22

TC SRM 663 div2 A ChessFloor 暴力的相关文章

TC SRM 665 DIV2 A LuckyXor 暴力

LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive integer consisting of only the digits 4 and 7.Given an int a, return an int b strictly greater than a, such that a XOR b is a lucky number. (See Notes fo

TC SRM 663 div2 B AABB 逆推

AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many English words only use the letters A and B. Examples of such words include "AB" (short for abdominal), "BAA" (the noise a sheep makes), &

TC SRM 664 div2 AB

#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; class BearCheats{ public: string eyesight(int A, int B){ char t[256]; string s1; sprintf(t, "%d", A); s1 = t; string s2; cha

TC SRM 664 div2 B BearPlaysDiv2 bfs

BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by moving some stones between three piles of stones. Initially, the piles contain A, B, and C stones, respectively. Limak's goal is to produce three equa

tc srm 636 div2 500

100的数据直接暴力就行,想多了... ac的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #include <vector> 8 #define LL __int64 9 const int maxn =

Topcoder SRM 663 Div2 Hard: CheeseRolling(状压DP)

Problem Statement   N people (where N is a power of 2) are taking part in a single-elimination tournament in cheese rolling. The diagram below illustrates the structure of the tournament bracket. The people entering the tournament are numbered from 0

TC SRM 636 Div2 C ChocolateDividingHard 二分

先把行合并,然后二分一下最小值就好. // BEGIN CUT HERE // END CUT HERE #line 5 "ChocolateDividingHard.cpp" #include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include

TC SRM 670 div2 Treestart

题目大意: 一个树状的棋盘,A,B两种棋子.初始时没有棋子重合,每一轮AB轮流移动任意个(包括不移动)自己的棋子,可以重合.如果某一时刻一格子上同时存在A和B两种棋子,则B获胜.A尽量使游戏进行的总轮数最多,B尽量在最少的轮数获胜(B 一定能获胜),输出最少轮数. 解题思路: 单独考虑A的每个棋子,每次分别扩展并跟新A和B能到的格子,如果A能到的格子中没有B不能到的,那么B胜利. 由于只有50个点,可以用状态压缩来让代码变得更加优美一点~! using namespace std; vector

SRM 630 DIV2

SRM 630 DIV2 第一次TC,本来以为AK了,结果1000分还是被系统cha掉了,不过倒是也cha掉了房间其他人赚了不少 A:字符串长度才50,直接简单的模拟即可 B:结点个数才10,先做一边floyd,找出两两之间路径,然后暴力枚举选哪些点,判断可不可以,如果可以的话,记录下最大个数 C:一开始的做法是,构造出rank数组后,对于连续的一段,都放a,然后最后一个放b即可,以为这样构造出来的肯定是字典序最小的,结果被系统cha掉了. 正确做法:一开始先构造出sa数组,暴力枚举每个位置,非