codeforces 1099E-Nice table
传送门:QAQQAQ
题意:给你一个矩阵只有AGCT,若对于每一个2*2的子矩阵中的四个字母互不相同,则称为这个矩阵是nice的,问至少变矩阵中的几个点可以使矩阵变nice
思路:没什么思路……就是大模拟。
我们先糊出一个结论:对于一个nice矩阵,要么每一行是两个字母循环出现,要么是每一列两个字母循环出现。(所以对于一些无从下手的题可以先模拟几个数据找普遍规律)
所以我们可以枚举左上角的2*2矩阵,再分类是关于行重复还是关于列重复,再关于每一个重复的行或列分类是ABABAB还是BABABA,然后爆搜答案和ans比较,用tmp维护再分类时的矩阵,用tmp来更新ans矩阵
代码量过大,本人在写程序时遇到以下问题:
1.更新时best矩阵忘清零
2.string直接赋值,而没有push_noback
3.智障地把ans=now写成了now=ans
代码(长度要破纪录了):
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
using namespace std;
int n,m;
string s[],best[];
vector<int> a[],tmp[];
int t[][],top=,ans=;
int fn(char c)
{
if(c=='A') return ;
else if(c=='C') return ;
else if(c=='G') return ;
else if(c=='T') return ;
}
char fc(int c)
{
if(c==) return 'A';
else if(c==) return 'C';
else if(c==) return 'G';
else if(c==) return 'T';
}
void print()
{
cout<<"That's OK!"<<endl;
}
int main()
{
//freopen("Nice.in","r",stdin);
//freopen("Nice.out","w",stdout);
ios::sync_with_stdio();
cin.tie();
cout.tie();
scanf("%d%d",&n,&m);
for (int i=;i<n;++i)
{
cin>>s[i];
for(int j=;j<m;j++) a[i].push_back(fn(s[i][j]));
}
for(int c1=;c1<=;c1++)
for(int c2=;c2<=;c2++)
for(int c3=;c3<=;c3++)
{
int c4=-c1-c2-c3;
if(c1==c2||c2==c3||c1==c3) continue;
t[++top][]=c1; t[top][]=c2;
t[top][]=c3; t[top][]=c4;
} for(int tt=;tt<=;tt++)
{
int c1=t[tt][],c2=t[tt][],c3=t[tt][],c4=t[tt][];
for(int b=;b<=;b++) //0:heng 1:shu
{
int now=;
if(!b)
{
for(int i=;i<n;i++) tmp[i].clear();
for(int i=;i<n;i++)
{
if(i%==)
{
if(i==)
{
for(int j=;j<m;j++) {
if(j%==)
{
if(c1!=a[i][j]) now++;
tmp[i].push_back(c1);
}
if(j%==)
{
if(c2!=a[i][j]) now++;
tmp[i].push_back(c2);
}
}
}
else
{
int tmp1=,tmp2=;
for(int j=;j<m;j++) {
if(j%==)
{
if(c1!=a[i][j]) tmp1++;
if(c2!=a[i][j]) tmp2++;
}
else
{
if(c1!=a[i][j]) tmp2++;
if(c2!=a[i][j]) tmp1++;
}
}
if(tmp1<=tmp2)
{
now+=tmp1;
for(int j=;j<m;j++)
if(j%==) tmp[i].push_back(c1);
else tmp[i].push_back(c2);
}
else
{
now+=tmp2;
for(int j=;j<m;j++)
if(j%==) tmp[i].push_back(c2);
else tmp[i].push_back(c1);
}
}
}
else
{
if(i==)
{
for(int j=;j<m;j++)
{
if(j%==)
{
if(c3!=a[i][j]) now++;
tmp[i].push_back(c3);
}
if(j%==)
{
if(c4!=a[i][j]) now++;
tmp[i].push_back(c4);
}
}
}
else
{
int tmp1=,tmp2=;
for(int j=;j<m;j++) {
if(j%==)
{
if(c3!=a[i][j]) tmp1++;
if(c4!=a[i][j]) tmp2++;
}
else
{
if(c3!=a[i][j]) tmp2++;
if(c4!=a[i][j]) tmp1++;
}
}
if(tmp1<=tmp2)
{
now+=tmp1;
for(int j=;j<m;j++)
if(j%==) tmp[i].push_back(c3);
else tmp[i].push_back(c4);
}
else
{
now+=tmp2;
for(int j=;j<m;j++)
if(j%==) tmp[i].push_back(c4);
else tmp[i].push_back(c3);
}
}
}
}
if(now<ans)
{
ans=now;
for(int i=;i<n;i++) best[i].clear();//!!!!!
for(int i=;i<n;i++)
for(int j=;j<m;j++) best[i].push_back(fc(tmp[i][j]));
//string不要直接赋值!!!
}
}
else
{
for(int j=;j<m;j++) tmp[j].clear();
for(int j=;j<m;j++)
{
if(j%==)
{
if(j==)
{
for(int i=;i<n;i++) {
if(i%==)
{
if(c1!=a[i][j]) now++;
tmp[j].push_back(c1);
}
if(i%==)
{
if(c3!=a[i][j]) now++;
tmp[j].push_back(c3);
}
}
}
else
{
int tmp1=,tmp2=;
for(int i=;i<n;i++) {
if(i%==)
{
if(c1!=a[i][j]) tmp1++;
if(c3!=a[i][j]) tmp2++;
}
else
{
if(c1!=a[i][j]) tmp2++;
if(c3!=a[i][j]) tmp1++;
}
}
if(tmp1<=tmp2)
{
now+=tmp1;
for(int i=;i<n;i++)
if(i%==) tmp[j].push_back(c1);
else tmp[j].push_back(c3);
}
else
{
now+=tmp2;
for(int i=;i<n;i++)
if(i%==) tmp[j].push_back(c3);
else tmp[j].push_back(c1);
}
}
}
else
{
if(j==)
{
for(int i=;i<n;i++) {
if(i%==)
{
if(c2!=a[i][j]) now++;
tmp[j].push_back(c2);
}
if(i%==)
{
if(c4!=a[i][j]) now++;
tmp[j].push_back(c4);
}
}
}
else
{
int tmp1=,tmp2=;
for(int i=;i<n;i++) {
if(i%==)
{
if(c2!=a[i][j]) tmp1++;
if(c4!=a[i][j]) tmp2++;
}
else
{
if(c2!=a[i][j]) tmp2++;
if(c4!=a[i][j]) tmp1++;
}
}
if(tmp1<=tmp2)
{
now+=tmp1;
for(int i=;i<n;i++)
if(i%==) tmp[j].push_back(c2);
else tmp[j].push_back(c4);
}
else
{
now+=tmp2;
for(int i=;i<n;i++)
if(i%==) tmp[j].push_back(c4);
else tmp[j].push_back(c2);
}
}
}
}
if(now<ans)
{
ans=now;//ans,now写反了。。。
for(int i=;i<n;i++) best[i].clear();//!!!!!
for(int i=;i<n;i++)
for(int j=;j<m;j++) best[i].push_back(fc(tmp[j][i]));
}
}
}
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++) printf("%c",best[i][j]);
puts("");
}
return ;
}
codeforces 1099E-Nice table的更多相关文章
- CodeForces 1099E - Nice table - [好题]
题目链接:https://codeforces.com/problemset/problem/1099/E You are given an $n×m$ table, consisting of ch ...
- Codeforces 417E Square Table(随机算法)
题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- codeforces D. Multiplication Table
http://codeforces.com/contest/448/problem/D 题意:一个n×m的矩阵,a[i][j]=i*j; 然后把a数组排序,找出第k个数. 思路:1-n×m二分枚举,然 ...
- Codeforces 22B Bargaining Table
http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...
- Codeforces #662C Binary Table
听说这是一道$ Tourist$现场没出的题 Codeforces #662C 题意: 给定$n*m的 01$矩阵,可以任意反转一行/列($0$变$1$,$1$变$0$),求最少$ 1$的数量 $ n ...
- Codeforces 40E Number Table - 组合数学
题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...
- Codeforces 233 D - Table
D - Table 思路:dp 首先,第i列的个数肯定和第i - n列个数一样,假设[i - n + 1, i - 1] 之间的个数之和为x,那么第i列和第i-n列的个数应该是n - x 那么我们可以 ...
- 【CODEFORCES】 C. Table Decorations
C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...
- codeforces 651E E. Table Compression(贪心+并查集)
题目链接: E. Table Compression time limit per test 4 seconds memory limit per test 256 megabytes input s ...
随机推荐
- 【POJ】1860 Currency Exchange
真是气skr人..没把d[]换成double...de了一上午的bug// 记得用G++提交啊 题目链接:http://poj.org/problem?id=1860 题意:告诉你n个点,m条路.起始 ...
- 如何 clean IntelliJ IDEA 中的工程
如何 clean IntelliJ IDEA 中的工程 1.点击“build”,选择“Build Artifacts” 2.点击“clean”,就可以了:然后重新,debug run 就完成了. ...
- Linux系统搭建Red5服务器
Linux系统搭建Red5服务器 Red5 是 支持Windows,Linux等多平台的RTMP流媒体服务器,Windows下搭建相对容易,图形界面操作比较简单,Linux服务器的环境下没有图形界面, ...
- asprise-ocr-api-sample 高价收破解版64 32位
asprise-ocr-api-sample验证码 高价收破解版64 32位 Reflector 8.5 打开自己的C#代码 完全100%的反编译了
- Tool Zip 破解
//侵权请联系我进行删除 email:YZFHKM@163.com 0x00 fcrackzip简单介绍 fcrackzip是一款专门破解zip类型压缩文件密码的工具,工具小巧方便.破解速度快,能使用 ...
- react 16更新
1.render新的返回类型 render方法支持两种新的返回类型:数组(由React元素组成)和字符串 2.错误处理 16之前,组件在运行期间如果执行出错,就会阻塞整个应用的渲染,这时候只能刷新页面 ...
- 如何有效管理Windows系统帐户权限
权限是Windows管理的基础,当然与Windows用户关系最密切,平时接触最多的是与帐户相关的权限.对于Windows帐户权限的管理,你是否完全了解呢?下面,笔者以Winsows XP为例进行相关测 ...
- java.sql.SQLSyntaxErrorException: ORA-00932: 数据类型不一致: 应为 NUMBER, 但却获得 BINARY
2019-07-24 17:24:35 下午 [Thread: http-8080-4][ Class:net.sf.ehcache.store.disk.Segment Method: net.sf ...
- 17.splash_case03
# python执行lua脚本 import requests from urllib.parse import quote lua = ''' function main(splash) retur ...
- Query Rewrite Plugins
[root@ZST1 ~] mysql -- </usr/local/mysql/share/install_rewriter.sql mydba@ [(none)]> create da ...