CodeForces 1099E - Nice table - [好题]
题目链接:https://codeforces.com/problemset/problem/1099/E
You are given an $n×m$ table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every $2×2$ square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First line contains two positive integers $n$ and $m$ — number of rows and columns in the table you are given $(2≤n,m,n×m≤300000)$. Then, $n$ lines describing the table follow. Each line contains exactly $m$ characters «A», «G», «C», «T».
Output
Output $n$ lines, $m$ characters each. This table must be nice and differ from the input table in the minimum number of characters.
Examples
Input
2 2
AG
CT
Output
AG
CT
Input
3 5
AGCAG
AGCAG
AGCAG
Output
TGCAT
CATGC
TGCAT
Note
In the first sample, the table is already nice. In the second sample, you can change $9$ elements to make the table nice.
题解:
一个 nice table 必然属于以下两种情况:
1、每行都由两个字符交替组成,相邻两行的字符集合交集为空;
2、每列都由两个字符交替组成,相邻两列的字符集合交集为空。
对于上述两种情况中的一种,不妨先对于每行,枚举其可能的字符集,而对于一个字符集,又有正序和逆序两种情况。
AC代码:
- #include<bits/stdc++.h>
- using namespace std;
- const int maxn=3e5+;
- const char choice[][]={{'A','C'},{'A','G'},{'A','T'},{'C','G'},{'C','T'},{'G','T'}};
- int n,m;
- string str[maxn];
- int ord[][maxn][],cnt[][maxn];
- string out[maxn];
- void print(int rc,int k)
- {
- for(int i=;i<n;i++) out[i]="";
- if(rc==) //R
- {
- for(int i=;i<n;i++)
- for(int j=;j<m;j++)
- out[i]+=choice[(i&)?-k:k][(j&)^ord[][i][k]];
- }
- else //C
- {
- for(int j=;j<m;j++)
- for(int i=;i<n;i++)
- out[i]+=choice[(j&)?-k:k][(i&)^ord[][j][k]];
- }
- for(int i=;i<n;i++) cout<<out[i]<<endl;
- }
- int main()
- {
- cin>>n>>m;
- for(int i=;i<n;i++) cin>>str[i];
- memset(cnt,,sizeof(cnt));
- for(int i=;i<n;i++)
- {
- for(int k=;k<;k++)
- {
- int now1=, now2=;
- for(int j=;j<m;j++)
- {
- now1+=(str[i][j]!=choice[(i&)?-k:k][j&]);
- now2+=(str[i][j]!=choice[(i&)?-k:k][(j&)^]);
- }
- ord[][i][k]=now1<now2?:; //0正序,1逆序
- cnt[][k]+=min(now1,now2);
- }
- }
- for(int j=;j<m;j++)
- {
- for(int k=;k<;k++)
- {
- int now1=, now2=;
- for(int i=;i<n;i++)
- {
- now1+=(str[i][j]!=choice[(j&)?-k:k][i&]);
- now2+=(str[i][j]!=choice[(j&)?-k:k][(i&)^]);
- }
- ord[][j][k]=now1<now2?:; //0正序,1逆序
- cnt[][k]+=min(now1,now2);
- }
- }
- int ans=0x3f3f3f3f,RC,K;
- for(int rc=;rc<=;rc++)
- {
- for(int k=;k<;k++)
- {
- if(cnt[rc][k]<ans) ans=cnt[rc][k], RC=rc, K=k;
- }
- }
- //cout<<ans<<endl;
- print(RC,K);
- }
(注:借鉴了https://www.luogu.org/blog/xht37/cf1098bcf1099e-nice-table的代码,到了这个点心态真的要放平……心态不稳代码基本不可能AC……)
CodeForces 1099E - Nice table - [好题]的更多相关文章
- Codeforces 417E Square Table(随机算法)
题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a ...
- Codeforces#441 Div.2 四小题
Codeforces#441 Div.2 四小题 链接 A. Trip For Meal 小熊维尼喜欢吃蜂蜜.他每天要在朋友家享用N次蜂蜜 , 朋友A到B家的距离是 a ,A到C家的距离是b ,B到C ...
- You Are Given a Decimal String... CodeForces - 1202B [简单dp][补题]
补一下codeforces前天教育场的题.当时只A了一道题. 大致题意: 定义一个x - y - counter :是一个加法计数器.初始值为0,之后可以任意选择+x或者+y而我们由每次累加结果的最后 ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题
A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...
- Codeforces 675C Money Transfers 思维题
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...
- Codeforces Gym 100531G Grave 水题
Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...
- Codeforces #662C Binary Table
听说这是一道$ Tourist$现场没出的题 Codeforces #662C 题意: 给定$n*m的 01$矩阵,可以任意反转一行/列($0$变$1$,$1$变$0$),求最少$ 1$的数量 $ n ...
- Codeforces 1137D - Cooperative Game - [交互题+思维题]
题目链接:https://codeforces.com/contest/1137/problem/D 题意: 交互题. 给定如下一个有向图: 现在十个人各有一枚棋子(编号 $0 \sim 9$),在不 ...
随机推荐
- APP安全测评checklist---Android
首先,你的app得先混淆:AndroidStudio 混淆打包 先来个checklist: 编号 检查项目 测评结果 1 明文传输用户名.密码和验证码等敏感信息. 2 不安全的本地存储. 3 泄漏后台 ...
- jQuery的deferred对象详解(转)
jQuery的开发速度很快,几乎每半年一个大版本,每两个月一个小版本. 每个版本都会引入一些新功能.今天我想介绍的,就是从jQuery 1.5.0版本开始引入的一个新功能----deferred对象. ...
- Spark2.3 HA集群的分布式安装
一.下载Spark安装包 1.从官网下载 http://spark.apache.org/downloads.html 2.从微软的镜像站下载 http://mirrors.hust.edu.cn/a ...
- RGMII_PHY测试笔记1 基于开发板MiS603-X25
RGMII_PHY测试笔记1 基于开发板MiS603-X25 作者:汤金元 日期:20150817 公司:南京米联电子科技有限公司 博客:http://blog.chinaaet.com/detail ...
- 开始逐步补充下相关Web知识,很多年没搞了....
<script type="text/javascript"> $(function(){ ShowProduct(); $("#ShowUserInfo&q ...
- windows下安装pycharm并连接Linux的python环境
1. 下载安装Pycharm专业版 具体方法略.Pycharm5激活方法参考http://www.cnblogs.com/snsdzjlz320/p/7110186.html 2. 添加配置连接远程服 ...
- 《转》推荐几个精致的web UI框架
1.Aliceui Aliceui是支付宝的样式解决方案,是一套精选的基于 spm 生态圈的样式模块集合,是 Arale 的子集,也是一套模块化的样式命名和组织规范,是写 CSS 的更好方式. git ...
- android的左右滑动效果实现-ViewFlipper
说到android的左右滑动效果我们可以说是在每个应用上面都可以看到这样的效果,不管是微博,还是QQ等.实现左右滑动的方式很多,有ViewPaer(不过这个和需要android-support-v4. ...
- 测试覆盖率工具:EclEmma
测试覆盖率工具:EclEmma 2016-08-26 目录 1 测试覆盖率实现技术2 EclEmma介绍3 EclEmma测试覆盖率指标4 EclEmma安装5 示例项目介绍 5.1 创建项目 5 ...
- JUnit+Mockito结合测试Spring MVC Controller
[本文出自天外归云的博客园] 概要简述 利用JUnit结合Mockito,再加上spingframework自带的一些方法,就可以组合起来对Spring MVC中的Controller层进行测试. 在 ...