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& ...
随机推荐
- 基础教程:Mac 电脑小白应该了解哪些东西?
文章素材来源:知乎 文章收录于:风云社区(www.scoee.com),提供1700多款mac软件下载. 本文提供给那些从 PC 阵营初入 Mac 的同学而准备的,我们希望从硬件和软件.设计风格和使用 ...
- BZOJ2815 拓扑排序 + LCA
https://www.lydsy.com/JudgeOnline/problem.php?id=2815 作为一个DAG图,结点之间又有这么明显的等级之分,很容易想到的是拓扑排序. 但是不管是正向的 ...
- 2017-12-15python全栈9期第二天第三节之使用while循环输出1到100的奇数,
#!/user/bin/python# -*- coding:utf-8 -*-count = 1while count <101: if count % 2 == 1: print(count ...
- JSON的简单使用_解析前台传来的JSON数据
package cn.rocker.json; import org.junit.Test; import net.sf.json.JSONArray; import net.sf.json.JSON ...
- 运维监控-Zabbix Server 使用QQ SMTP发送邮件报警及定制报警内容
运维监控-Zabbix Server 使用QQ SMTP发送邮件报警及定制报警内容 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客采用腾讯邮箱,想必大家都对QQ很了解,所以 ...
- HDU 6374(拼三角形 **)
题意是在给定的线段长中挑选出能拼成三角形的最长的三条边,输出三角形的周长.先对所有边排序,从大到小,满足两较短边之和大于第三边就输出,若从未输出过就输出 -1 #include <iostrea ...
- sqlserver2012 offset分页
select ID,UserName from user order by ID OFFSET (10 * (50-1)) ROW FETCH NEXT 10 rows only
- 腾讯云cos封装
public class CosUtil { int _appId = xxxxx; string _secretId = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
- Entity Framework 6.0 常见异常及解决办法
Ø 简介 本文主要记录 EF(Entity Framework) 在平时的开发中可能遇到的异常,以及应该如何去解决. 1. System.InvalidOperationException 1) ...
- CountDownLatch学习
看了几篇博客,说用CountDownLatch实现一个先执行完子线程,再执行主线程的例子.因此写一篇博客总结一下. 一.CountDownLatch了解 1.CountDownLatch继承了Abst ...