• 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;
        }
    };
  • 相关阅读:
    codevs 1160 蛇形矩阵
    进程同步-进程内部也需要锁
    进程间通讯-3(Manager)-实现数据的同时修改
    进程间通讯-2(pipe)
    python 中的queue 与多进程--待继续
    进程间通讯-1-传递函数的方法
    多进程
    queue队列
    python-输出颜色显示
    python深浅copy-转自EVA的博客
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4672201.html
Copyright © 2020-2023  润新知