hyw
zhunbeihaolema · · 个人记录
#include<bits/stdc++.h>
using namespace std;
int n,m,z;
long long a[5001][5001];
int t1[5001],t2[5001];
int x,y;
int main(){
cin>>n>>m>>z;
int cnt=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
a[i][j]=cnt;
cnt++;
}
}
for(int i=1;i<=n;i++){
t1[i]=i;
}
for(int j=1;j<=m;j++){
t2[j]=j;
}
for(int i=1;i<=z;i++){
int a,b,c;
cin>>a>>b>>c;
if(a==1){
swap(t1[b],t1[c]);
}else if(a==2){
swap(t2[b],t2[c]);
}
}
cin>>x>>y;
long long r=t1[x];
long long c=t2[y];
long long sum=(r-1)*m+c;
cout<<sum;
}
#include<bits/stdc++.h>
using namespace std;
bool r[10][10],c[10][10],t[10][10];
int main(){
bool ok=true;
for(int i=1;i<=9;i++){
string s;
cin>>s;
for(int j=1;j<=9;j++){
char ch=s[j-1];
if(ch!='.'){
int g=((i-1)/3)*3+(j-1)/3;
if(r[i][ch-'0']==true||c[j][ch-'0']==true||t[g][ch-'0']==true){
ok=false;
}else{
r[i][ch-'0']=true;
c[j][ch-'0']=true;
t[g][ch-'0']=true;
}
}
}
}
if(ok==true){
cout<<"YES";
}else{
cout<<"NO";
}
return 0;
}