跳到正文

个人记录

hyw

zhunbeihaolema约 3 分钟
原文
文章信息与版本

文章信息

发布
2026年10月6日
收录
2026年10月6日
更新
2026年11月17日
篇幅
约 3 分钟

版本

  1. v2当前
  2. v1
C++
#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;
}
C++
#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;
}
原文