CF1098B/CF1099E Nice table
题目地址: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的更多相关文章
- FCKeditor使用方法技术详解
转载自 http://www.cnblogs.com/cchyao/archive/2010/07/01/1769204.html 1.概述 FCKeditor是目前最优秀的可见即可得网页编辑器之一, ...
- mysql slow query---pt-query-digest----db structure consistency,monitor table records before and after transaction.
将数据库脚本纳入版本管理是很必要的,尤其对于需要在客户那里部署升级的系统. 对于Python Django等框架,由于数据库是通过Model生成的,因此框架本身包括数据库升级工具,并通过代码版本间接管 ...
- 学习mongo系列(一) win/mac安装 解析 连接
一.安装mongo数据库 下载链接https://www.mongodb.org/downloads, 在执行如下命令的时候事先按照目录新建如下的目录:(如果数据库安装在D盘就在D盘的根目录下建)&q ...
- SAP接口编程 之 JCo3.0系列(03) : Table参数
Table参数作为export parameter BAPI_COMPANYCODE_GETDETAIL是一个适合演示的函数,没有import paramter参数,调用后COMPANYCODE_GE ...
- 在iOS中怎样创建可展开的Table View?(下)
接上篇:在iOS中怎样创建可展开的Table View?(上) 展开和合拢 我猜这部分可能是你最期望的了,因为本次教程的目标将会在在部分实现.第一次我们设法让顶层的cell,在它们点击的时候展开或者合 ...
- 在iOS中怎样创建可展开的Table View?(上)
原文地址 本文作者:gabriel theodoropoulos 原文:How To Create an Expandable Table View in iOS 原文链接 几乎所有的app都有一个共 ...
- Html table 实现Excel多格粘贴
Html table 实现Excel多格粘贴 电商网站的后台总少不了各种繁杂数据的录入,旁边的运营妹子录完第138条商品的时候,终于忍不住转身吼到:为什么后台的录入表不能像Excel那样多行粘贴!!! ...
- iOS开发——OC篇&消息传递机制(KVO/NOtification/Block/代理/Target-Action)
iOS开发中消息传递机制(KVO/NOtification/Block/代理/Target-Action) 今晚看到了一篇好的文章,所以就搬过来了,方便自己以后学习 虽然这一期的主题是关于Fou ...
- css控制div显示/隐藏方法及2种方法比较原码 - czf164的专栏 - 博客频道 - CSDN.NET
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
随机推荐
- chrome截图全网页
1.F12 2.ctrl+shift+p 3.输入:capture 4.选择Capture full size screenshot
- jsp+servlet+jdbc实现表单提交
1.新建一个maven工程,选webapp模板 2.安装tomcat https://tomcat.apache.org/download-80.cgi 下载解压到自定义目录上 ps:在全局变量加上J ...
- JavaSE_坚持读源码_HashMap对象_get_Java1.7
当你从HashMap里面get时,你其实在干什么? /** * Returns the value to which the specified key is mapped, * or {@code ...
- 11:12:21.924 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
11:12:21.924 [main] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class or ...
- C++回顾day02---<拷贝构造函数:重点>
一:补充---无参构造函数(默认无参构造函数)在实例化对象时注意点 (一)若没有写构造函数,则类会含有一个默认无参构造函数 (二)若自定义一个构造函数,则类不会提供默认构造函数 class A { p ...
- JAVA核心技术I---JAVA基础知识(列表List)
一:List了解 (一)List:列表 –有序的Collection –允许重复元素 –{,,,{,},,} (二)List:主要实现 同步/非同步:针对线程而言 –ArrayList(非同步的) – ...
- 【2】【leetcode-105,106】 从前序与中序遍历序列构造二叉树,从中序与后序遍历序列构造二叉树
105. 从前序与中序遍历序列构造二叉树 (没思路,典型记住思路好做) 根据一棵树的前序遍历与中序遍历构造二叉树. 注意:你可以假设树中没有重复的元素. 例如,给出 前序遍历 preorder = [ ...
- 026、一张图搞懂docker(2019-01-21 周一)
参考https://www.cnblogs.com/CloudMan6/p/6961665.html
- 多线程Thread类的方法
创建多个线程的第一种方法 1.定义一个Thread类的子类,比如MyThread类 2.重写Thread的run方法,设置线程任务 3.创建Mythread类的对象 4.调用方法start(),开启新 ...
- C#一例绘制字体不清晰的解决办法
public static Bitmap GetPieWithText(String text, Color color, Color fontColor,Font font) { ; Bitmap ...