题目地址:CF1098B/CF1099E Nice table

显然,a nice table需要满足如下条件:

要么,每行都由两个字符交替组成,相邻两行的字符均不相同

要么,每列都由两个字符交替组成,相邻两列的字符均不相同

然后枚举就完事啦

代码:

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const string str = "ATGC";
vector<string> s, tmp, ans;

int main() {
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        string st;
        cin >> st;
        s.push_back(st);
    }
    int ansmin = INF, now;
    for (int c1 = 0; c1 < 4; c1++)
        for (int c2 = c1 + 1; c2 < 4; c2++) {
            string t;
            set<int> st;
            for (int i = 0; i < 4; i++) st.insert(i);
            st.erase(c1);
            st.erase(c2);
            set<int>::iterator it = st.begin();
            t.push_back(str[c1]);
            t.push_back(str[c2]);
            t.push_back(str[*(it++)]);
            t.push_back(str[*it]);
            now = 0;
            tmp.clear();
            for (int i = 0; i < n; i++) {
                tmp.push_back("");
                int b = (i & 1) << 1;
                int cnt1 = 0, cnt2 = 0;
                for (int j = 0; j < m; j++) {
                    if (s[i][j] != t[b+(j&1)]) ++cnt1;
                    if (s[i][j] != t[b+((j&1)^1)]) ++cnt2;
                }
                if (cnt1 < cnt2)
                    for (int j = 0; j < m; j++)
                        tmp[i].push_back(t[b+(j&1)]);
                else
                    for (int j = 0; j < m; j++)
                        tmp[i].push_back(t[b+((j&1)^1)]);
                now += min(cnt1, cnt2);
            }
            if (now < ansmin) {
                ans = tmp;
                ansmin = now;
            }
            now = 0;
            tmp.clear();
            for (int i = 0; i < n; i++) tmp.push_back("");
            for (int j = 0; j < m; j++) {
                int b = (j & 1) << 1;
                int cnt1 = 0, cnt2 = 0;
                for (int i = 0; i < n; i++) {
                    if (s[i][j] != t[b+(i&1)]) ++cnt1;
                    if (s[i][j] != t[b+((i&1)^1)]) ++cnt2;
                }
                if (cnt1 < cnt2)
                    for (int i = 0; i < n; i++)
                        tmp[i].push_back(t[b+(i&1)]);
                else
                    for (int i = 0; i < n; i++)
                        tmp[i].push_back(t[b+((i&1)^1)]);
                now += min(cnt1, cnt2);
            }
            if (now < ansmin) {
                ans = tmp;
                ansmin = now;
            }
        }
    for (int i = 0; i < n; i++) cout << ans[i] << endl;
    return 0;
}

CF1098B/CF1099E Nice table的更多相关文章

  1. FCKeditor使用方法技术详解

    转载自 http://www.cnblogs.com/cchyao/archive/2010/07/01/1769204.html 1.概述 FCKeditor是目前最优秀的可见即可得网页编辑器之一, ...

  2. mysql slow query---pt-query-digest----db structure consistency,monitor table records before and after transaction.

    将数据库脚本纳入版本管理是很必要的,尤其对于需要在客户那里部署升级的系统. 对于Python Django等框架,由于数据库是通过Model生成的,因此框架本身包括数据库升级工具,并通过代码版本间接管 ...

  3. 学习mongo系列(一) win/mac安装 解析 连接

    一.安装mongo数据库 下载链接https://www.mongodb.org/downloads, 在执行如下命令的时候事先按照目录新建如下的目录:(如果数据库安装在D盘就在D盘的根目录下建)&q ...

  4. SAP接口编程 之 JCo3.0系列(03) : Table参数

    Table参数作为export parameter BAPI_COMPANYCODE_GETDETAIL是一个适合演示的函数,没有import paramter参数,调用后COMPANYCODE_GE ...

  5. 在iOS中怎样创建可展开的Table View?(下)

    接上篇:在iOS中怎样创建可展开的Table View?(上) 展开和合拢 我猜这部分可能是你最期望的了,因为本次教程的目标将会在在部分实现.第一次我们设法让顶层的cell,在它们点击的时候展开或者合 ...

  6. 在iOS中怎样创建可展开的Table View?(上)

    原文地址 本文作者:gabriel theodoropoulos 原文:How To Create an Expandable Table View in iOS 原文链接 几乎所有的app都有一个共 ...

  7. Html table 实现Excel多格粘贴

    Html table 实现Excel多格粘贴 电商网站的后台总少不了各种繁杂数据的录入,旁边的运营妹子录完第138条商品的时候,终于忍不住转身吼到:为什么后台的录入表不能像Excel那样多行粘贴!!! ...

  8. iOS开发——OC篇&消息传递机制(KVO/NOtification/Block/代理/Target-Action)

     iOS开发中消息传递机制(KVO/NOtification/Block/代理/Target-Action)   今晚看到了一篇好的文章,所以就搬过来了,方便自己以后学习 虽然这一期的主题是关于Fou ...

  9. css控制div显示/隐藏方法及2种方法比较原码 - czf164的专栏 - 博客频道 - CSDN.NET

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

随机推荐

  1. Intellij Idea识别Java Web项目

    使用maven生成一个Java项目,手动添加相应的web目录WEB_INF,web.xml等,此时idea没有自动识别为web项目,此时编辑web.xml文件会出现一些不该出现的错误,需要做的就是让i ...

  2. OS + Ubuntu ARM Android

    s 1. Ubuntu 18.04 ISO的下载路径参考:https://www.ubuntu.com/download/server/arm 2. Android SDK下载链接:https://p ...

  3. java 中数据的强制转换 和计算的补码运算

    原码 反码 补码的定义与运算 1原码: 原码是将十进制或者其他进制的数转换为二进制表示(且要根据数据的类型转换) 如:130 (默认是Int类型,则是4个字节) 原码是:00000000 000000 ...

  4. windows 中查找占用某个端口的进程并杀死的命令

    如图所示

  5. java中变量关系

  6. 函数的作用域、global与nonlocal

    global 表示不再使用局部局部作用域中的内容,而是改用全局作用域中的变量 a = 100 def func(): global a # 表示不再局部创建这个变量,而是直接使用这个全局的a a = ...

  7. mysql驱动参数变化

    在java平台使用的mysql jdbc驱动为:mysql-connector-java. 在项目中添加如下依赖: <dependency> <groupId>mysql< ...

  8. Spring boot 配置自己的拦截器

    框架使用的是spring boot 2.0 首先,自定义拦截器实现HandlerInterceptor接口,preHandler是在执行controller方法前执行的  此外还有两个方法,具体作用最 ...

  9. [Java] [查找文件] [递归]]

    // 工具方法 private static FilenameFilter getFilter(final String mode) { return new FilenameFilter() { P ...

  10. Lua 函数链功能

    函数链 http://lua-users.org/wiki/FiltersSourcesAndSinks A chain is a function that combines the effect ...