传送门: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的更多相关文章

  1. CodeForces 1099E - Nice table - [好题]

    题目链接:https://codeforces.com/problemset/problem/1099/E You are given an $n×m$ table, consisting of ch ...

  2. Codeforces 417E Square Table(随机算法)

    题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a ...

  3. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

  4. codeforces D. Multiplication Table

    http://codeforces.com/contest/448/problem/D 题意:一个n×m的矩阵,a[i][j]=i*j; 然后把a数组排序,找出第k个数. 思路:1-n×m二分枚举,然 ...

  5. Codeforces 22B Bargaining Table

    http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...

  6. Codeforces #662C Binary Table

    听说这是一道$ Tourist$现场没出的题 Codeforces #662C 题意: 给定$n*m的 01$矩阵,可以任意反转一行/列($0$变$1$,$1$变$0$),求最少$ 1$的数量 $ n ...

  7. Codeforces 40E Number Table - 组合数学

    题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...

  8. Codeforces 233 D - Table

    D - Table 思路:dp 首先,第i列的个数肯定和第i - n列个数一样,假设[i - n + 1, i - 1] 之间的个数之和为x,那么第i列和第i-n列的个数应该是n - x 那么我们可以 ...

  9. 【CODEFORCES】 C. Table Decorations

    C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...

  10. codeforces 651E E. Table Compression(贪心+并查集)

    题目链接: E. Table Compression time limit per test 4 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. USACO2004 cube stacking /// 带权并查集 oj1302

    题目大意: 以N ( 1 ≤ N ≤ 30,000 )个堆栈开始,每个堆栈包含一个单独的立方体.执行P(1≤ P ≤100,000)的操作. 有两种类型的操作:移动和计数. *在移动操作中,将 包含方 ...

  2. 【图论】tarjan

    刚接触tarjan,tarjan其实更多是用来找强联通分量.我这里呢,是看qsc的视频学的.卿学姐讲的其实很清楚啦. 我这里只是做个整理. low[]:表示能到达这个点的最小编号.[树枝边].啊,其实 ...

  3. "_CMTimeGetSeconds", referenced from:

    CMTime is defined in the CoreMedia.framework. Add that framework to your project.

  4. c结构体指针使用

    #include <stdio.h> #include<stdlib.h> #include<string.h> typedef struct _Date { un ...

  5. AndroidStudio 搜索导入自己需要的库

    前言 在Androidx的库应用后,导致有需多系统组件库需要重新 implementation 升级为Androidx, 但是你可能会发现不知道怎么导入他们.  当然除了导入Android的组件库,还 ...

  6. Flask框架图

  7. Xshell 排版错乱问题

  8. WebAPI介绍

    Web API介绍 API的概念 API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访 ...

  9. JavaScript的函数进阶

    函数进阶 1立即执行函数表达式 立即执行的函数表达式的英文全称为Immediately Invoked Function Expression,简称就为IIFE.这是一个如它名字所示的那样,在定义后就 ...

  10. VS2010-MFC(字体和文本输出:文本输出)

    转自:http://www.jizhuomi.com/software/241.html 上一节讲了CFont字体类,本节主要讲解文本输出的方法和实例. 文本输出过程 在文本输出到设备以前,我们需要确 ...