C2. Errich-Tac-Toe (Hard Version)
https://codeforces.com/contest/1450/problem/C2
這輩子都做不出陰間構造題.jpg
這題關鍵想到用i+j...
連續的橫豎3個,他們的(i+j)也是連續的
所以我們只要(i+j)%3中的0,1,2的某一個全部取反就行了,總有一個的數量是<=sum/3
對於XO兩個,我們就找出x,y,為了防止反轉以後出現新的3連,所以x要保證不等於y
我們知道最差情況就是Xsum/3,Xsum0/3+1,Xsum0/3+1或者Xsum/3,Xsum/3,Xsum/3+1這樣
可知我們無論X,O分別的總數%3餘多少,都能找出一個x,y使得總共變換數量<=sum/3
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxl=1010;
int n,m,k,tot,cas,ans;
int cnt[3][2];
char a[maxl][maxl],b[maxl][maxl];
bool visr[maxl],visc[maxl];
char s[maxl];
inline void prework()
{
scanf("%d",&n);
for(int i=0;i<3;i++)
cnt[i][0]=cnt[i][1]=0;
for(int i=1;i<=n;i++)
{
scanf("%s",a[i]+1);
for(int j=1;j<=n;j++)
if(a[i][j]=='O')
cnt[(i+j)%3][0]++;
else if(a[i][j]=='X')
cnt[(i+j)%3][1]++;
}
}
inline void mainwork()
{
int x,y,sum=0;
for(int i=0;i<3;i++)
for(int j=0;j<=1;j++)
sum+=cnt[i][j];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
if(i!=j && cnt[i][0]+cnt[j][1]<=sum/3)
{
x=i;y=j;
break;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(a[i][j]=='O' && (i+j)%3==x)
a[i][j]='X';
else if(a[i][j]=='X' && (i+j)%3==y)
a[i][j]='O';
}
inline void print()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
printf("%c",a[i][j]);
puts("");
}
}
int main()
{
int t=1;
scanf("%d",&t);
for(cas=1;cas<=t;cas++)
{
prework();
mainwork();
print();
}
return 0;
}
相關文章
- C2. Potions (Hard Version)
- C2. Magnitude (Hard Version)
- C2. Adjust The Presentation (Hard Version)
- CF 2010 C2. Message Transmission Error (hard version) (*1700) 字串+雜湊Error字串
- Reverse Card (Hard Version)
- D2. Reverse Card (Hard Version)
- D2. Set To Max (Hard Version)
- 11-雜湊4 Hashing - Hard Version
- CF1998E2 Eliminating Balls With Merging (Hard Version)
- 題解:CF1537E2 Erase and Extend (Hard Version)
- [題解]CF1990E2 Catch the Mole(Hard Version)
- CF1967B2 Reverse Card (Hard Version) 題解
- CF1264D1/2 Beautiful Bracket Sequence (easy/hard version)Racket
- CF1264D2 Beautiful Bracket Sequence (hard version) 題解Racket
- CF1967B2. Reverse Card (Hard Version) 題解 數學題
- git reset --hard HEAD^Git
- NP-Hard問題
- Is programming an Operating System so hard?
- TensorFlow 報錯 CUDA driver version is insufficient for CUDA runtime version
- IDBDatabase.versionDatabase
- MySQL Version TokensMySql
- 理解Semantic Version
- 容斥定理 AtCoder——FizzBuzz Sum Hard
- git程式碼回退--hard的坑Git
- 解決The given version [xx] is not supported, only version 1 to 10 is supported in this buildUI
- ORA-39358: Export dump file version 12.1.0 not compatible with target version 11Export
- Catch the Mole(Easy Version)
- JDK版本 - Major VersionJDK
- Prefix Flip (Easy Version)
- PJSIP version 2.7.2 For AndroidJSAndroid
- Maven多模組中,parent version如何採用自定${version}表示Maven
- [AGC001E] BBQ Hard題解GC
- DevOps is Hard、DevSecOps is Even Harder. --- Enterprise Holdidev
- 2020MRCTF(Re)-Hard-to-go(WP)Go
- BZOJ4589: Hard Nim(FWT 快速冪)
- General->Identity->VersionIDE
- iOS--Unsupported swift versioniOSSwift
- 165. Compare Version Numbers