题解

205 条题解

  • 0
    @ 2016-06-01 20:15:16

    这段代码可读性还行。
    #include<iostream>
    using namespace std;
    int arr[20][20];
    void read(void)//用于每次读入完整的81个数字
    {
    for (int i = 1; i <= 9; i++)
    for (int j = 1; j <= 9; j++)
    cin >> arr[i][j];
    }
    bool judge(int nine[])//每次nine里都会存9个数字,这个函数用于判断这九个数字是否违反规则
    {
    bool *savefalse = new bool[10];
    for (int i = 1; i <= 9; i++)
    savefalse[i] = false;
    for (int i = 1; i <= 9; i++)
    {
    if (savefalse[nine[i]] == true)
    {
    delete[] savefalse;
    return false;
    }
    else savefalse[nine[i]] = true;
    }
    return true;
    }
    void choose_sudoku(int nine[], int a, int b)//根据给的a和b,选择相应区间里的元素放入数组nine中
    {
    int subscript = 1;
    for (int i = a; i <= a + 2; i++)
    for (int j = b; j <= b + 2; j++)
    nine[subscript++] = arr[i][j];
    }
    bool handle(void)//用于判断每个含有81个数字的数独是否违反规则
    {
    int nine[10];
    for (int i = 1; i <= 9; i++)//判断9行横着的数字是否违反规则
    {
    for (int j = 1; j <= 9; j++)
    nine[j] = arr[i][j];
    if (judge(nine)==true) continue;
    else return false;
    }
    for (int j = 1; j <= 9; j++)//判断9列竖着的数字是否违反规则
    {
    for (int i = 1; i <= 9; i++)
    nine[i] = arr[i][j];
    if (judge(nine) == true) continue;
    else return false;
    }

    for (int i = 1; i <= 9; i += 3)//判断9个小方格(每个小方格含有9个数)是否违反规则
    {
    for (int j = 1; j <= 9; j += 3)
    choose_sudoku(nine, i, j);
    if (judge(nine) == true) continue;
    else return false;
    }
    return true;
    }
    int main()
    {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
    read();
    if (handle() == true) cout << "Right"<<endl;
    else cout << "Wrong"<<endl;
    }
    //system("pause");
    return 0;
    }

  • 0
    @ 2016-05-26 20:56:52

    #include<iostream>
    #include<cstdio>
    using namespace std;
    int a[10][10];
    int b[10][10],i,j;
    int love(){
    for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
    b[i][a[i][j]]++;
    if(b[i][a[i][j]]>1){
    cout<<"Wrong"<<endl;
    return 0;
    }
    }
    }
    for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
    b[i][j]=0;
    }
    }
    for(j=1;j<=9;j++){

    for(i=1;i<=9;i++){
    b[j][a[i][j]]++;
    if(b[j][a[i][j]]>1){
    cout<<"Wrong"<<endl;
    return 0;
    }
    }
    }
    for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
    b[i][j]=0;
    }
    }
    int m,n;
    int z=1;

    for(i=1;i<=9;i+=3){

    for(j=1;j<=9;j+=3){
    for(m=i;m<=i+2;m++){

    for(n=j;n<=j+2;n++){
    b[z][a[m][n]]++;
    if(b[z][a[m][n]]>1){
    cout<<"Wrong"<<endl;
    return 0;
    }
    }
    }
    z++;
    }
    }
    return 1;
    }
    int main(){
    //freopen("shudu.in","r",stdin);
    //freopen("shudu.out","w",stdout);
    int k;
    cin>>k;
    while(k--){
    for(i=1;i<=9;i++){
    for(j=1;j<=9;j++){
    cin>>a[i][j];
    b[i][j]=0;
    }
    }
    if(love()==1){
    cout<<"Right"<<endl;
    }

    }
    return 0;
    }

  • 0
    @ 2016-04-09 14:05:54
    #include<iostream>
    using namespace std;
    #include<cstdio>
    #include<algorithm>
    int n,a[21][10][10];
    int b[9];
    void shuru();
    void sd();
    bool searchh(int i);
    bool searchs(int i);
    bool searchz(int i);
    bool ll(int i,int x,int y);
    int main(){
        //freopen("slar.in","r",stdin);
        //freopen("slar.out","w",stdout);
        shuru();
        sd();
        //fclose(stdout);
        return 0;
    }
    void shuru(){
        cin>>n;
        for(int i=1;i<=n;++i){
            for(int x=1;x<=9;++x){
                for(int y=1;y<=9;++y){
                    cin>>a[i][x][y];
                }
            }
        }
    }
    void sd(){
        for(int i=1;i<=n;++i){
            if(searchh(i)&&searchs(i)&&searchz(i)){
                cout<<"Right"<<endl;
            }else{
                cout<<"Wrong"<<endl;
            }
        }
    }
    bool searchh(int i){
        bool flag=true;
        for(int x=1;x<=9;++x){
            int ans=0;
            for(int y=1;y<=9;++y){
                b[ans++]=a[i][x][y];
            }
        }
        sort(b,b+9);
        for(int I=0;I<9;++I){
            if(b[I]!=I+1){
                flag=false;
                break;
            }
        }
        return flag;
    }
    bool searchs(int i){
        bool flag=true;
        for(int y=1;y<=9;++y){
            int ans=0;
            for(int x=1;x<=9;++x){
                b[ans++]=a[i][x][y];
            }
            
        }
        sort(b,b+9);
        for(int I=0;I<9;++I){
            if(b[I]!=I+1){
                flag=false;
                break;
            }
        }
        return flag;
    }
    bool searchz(int i){
        bool flag=true;
        for(int x=2;x<=8;x=x+3){
            for(int y=2;y<=8;y=y+3){
                if(ll(i,x,y)==false){
                    flag=false;
                    break;
                }
            }
        }
        return flag;
    }
    bool ll(int i,int x,int y){
        int ans=0;bool flag=true;
        for(int q=y-1;q<=y+1;++q){
            for(int w=x-1;w<=x+1;++w){
                b[ans++]=a[i][q][w];
            }
        }
        sort(b,b+9);
        for(int I=0;I<9;++I){
            if(b[I]!=I+1){
                flag=false;
                break;
            }
        }
        return flag;
    }
    
  • 0
    @ 2016-03-24 22:59:11
    var a:array [1..9,1..9] of longint;
        n,i,j,k:longint;
    function pd:boolean;
      var f:array [1..9] of boolean;
          i,j,k,l:longint;
      begin
        for i:=1 to 9 do
        begin
          fillchar(f,sizeof(f),0);
          for j:=1 to 9 do
            if f[a[i,j]] then exit(false) else f[a[i,j]]:=true;
        end;
        for i:=1 to 9 do
        begin
          fillchar(f,sizeof(f),0);
          for j:=1 to 9 do
            if f[a[j,i]] then exit(false) else f[a[j,i]]:=true;
        end;
        for i:=0 to 2 do
          for j:=0 to 2 do
          begin
            fillchar(f,sizeof(f),0);
            for k:=i*3+1 to i*3+3 do
              for l:=j*3+1 to j*3+3 do
                if f[a[k,l]] then exit(false) else f[a[k,l]]:=true;
          end;
        exit(true);
      end;
    begin
      readln(n);
      for k:=1 to n do
      begin
        for i:=1 to 9 do
        begin
          for j:=1 to 9 do read(a[i,j]);
          readln;
        end;
        if pd then writeln('Right')
        else writeln('Wrong');
      end;
    end.
    

    仓促写完没试过数据就提交了居然ac了,看来不难

  • 0
    @ 2016-03-13 18:12:59

    by Eden
    c++
    #include <iostream>
    #define ref(i,x,y)for(int i=x;i<=y;i++)
    using namespace std;
    int n,a[10][10],b[10];
    int main()
    {
    cin>>n;
    ref(i,1,n)
    {
    bool bo=1;
    ref(j,1,9)
    ref(k,1,9)
    cin>>a[j][k];
    ref(j,1,9)
    {
    ref(k,1,9)b[k]=0;
    ref(k,1,9)if(b[a[j][k]])
    bo=0;
    else b[a[j][k]]=1;
    ref(k,1,9)b[k]=0;
    ref(k,1,9)if(b[a[k][j]])
    bo=0;
    else b[a[k][j]]=1;
    }
    ref(j,1,3)
    ref(k,1,3)
    {
    ref(i1,1,9)b[i1]=0;
    ref(i1,j*3-2,j*3)
    ref(i2,k*3-2,k*3)
    if(b[a[i1][i2]])bo=0;
    else b[a[i1][i2]]=1;
    }
    if(bo)cout<<"Right"<<endl;
    else cout<<"Wrong"<<endl;
    }
    }

  • 0
    @ 2016-03-12 22:28:25
    function judge():boolean;
    var i,j,x,m,n,t:integer;res:boolean;
      line,column:array[1..9] of set of 1..9;
      grid:array[0..2,0..2] of set of 1..9;
    
    begin
      res:=true;
      for i:=1 to 9 do begin
        line[i]:=[];
        column[i]:=[];
      end;
      for i:=0 to 2 do
        for j:=0 to 2 do grid[i,j]:=[];
      for i:=1 to 9 do
        for j:=1 to 9 do begin
          read(x);
          if res then
            if (x in line[i]) or (x in column[j]) or
               (x in grid[(i-1) div 3,(j-1) div 3]) then res:=false
            else begin
              line[i]:=line[i]+[x];
              column[j]:=column[j]+[x];
              grid[(i-1) div 3,(j-1) div 3]:=grid[(i-1) div 3,(j-1) div 3]+[x];
            end;
        end;
      judge:=res;
    end;
    
    var n,i:integer;
      a:array[0..50] of boolean;
    begin
      read(n);
      for i:=1 to n do
        a[i]:=judge();
      for i:=1 to n do
        if a[i] then writeln('Right') else writeln('Wrong');
    end.
    
  • 0
    @ 2016-02-22 13:37:41
    program exercise(input,output);
    var n,k,i,j,x:longint;
        a,b:array[1..9,1..9]of boolean;
        c:array[1..17,1..9]of boolean;
        ch:boolean;
    function check():boolean;
    begin
         ch:=true;
         for i:=1 to 9 do
              for j:=1 to 9 do
                begin
                   read(x);
                   if a[i,x] or b[j,x] or c[((i-1) div 3)*3+(j-1) div 3+1,x] then
                        ch:=false;
                   a[i,x]:=true;
                   b[j,x]:=true;
                   c[((i-1) div 3)*3+(j-1) div 3+1,x]:=true;
                end;
         exit(ch);
    end;
    begin
         readln(n);
         for k:=1 to n do
           begin
              fillchar(a,sizeof(a),false);
              fillchar(b,sizeof(b),false);
              fillchar(c,sizeof(c),false);
              if check() then
                   writeln('Right')
              else
                   writeln('Wrong');
           end;
    end.
    
  • 0
    @ 2016-02-18 22:25:37

    教大家一种巧妙地de法。是我以前见到过的。
    ```
    /* ***********************************************
    Author :guanjun
    Created Time :2016/2/18 21:37:42
    File Name :vijosp1335.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10000+10
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;

    bool cmp(int a,int b){
    return a>b;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
    #endif
    //freopen("out.txt","w",stdout);
    int row[10][10],col[10][10],sq[10][10];
    int t,a;
    cin>>t;
    while(t--){
    cle(row),cle(col);cle(sq);
    for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
    cin>>a;
    row[i][a]=1;
    col[j][a]=1;
    int x=(i-1)/3*3+(j-1)/3;
    sq[x][a]=1;
    }
    }
    int mark=0;
    for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
    if(col[j][i]==0||row[i][j]==0||!sq[i-1][j]){mark=1;break;}
    }
    if(mark)break;
    }
    if(mark)puts("Wrong");
    else puts("Right");

    }
    return 0;
    }

  • 0
    @ 2016-02-12 18:31:19

    Pascal AC
    var n,k,i,j,l,p:longint;
    a:array[1..9,1..9]of longint;
    b:array[1..9]of longint;
    begin
    readln(n);
    for k:=1 to n do
    begin
    for i:=1 to 9 do
    begin
    for j:=1 to 9 do
    read(a[i,j]);
    readln;
    end;
    fillchar(b,sizeof(b),0);
    p:=0;
    for i:=1 to 9 do
    begin
    fillchar(b,sizeof(b),0);
    for j:=1 to 9 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    end;
    for i:=1 to 9 do
    begin
    fillchar(b,sizeof(b),0);
    for j:=1 to 9 do
    inc(b[a[j,i]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    end;
    fillchar(b,sizeof(b),0);
    for i:=1 to 3 do
    for j:=1 to 3 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=1 to 3 do
    for j:=4 to 6 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=1 to 3 do
    for j:=7 to 9 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=4 to 6 do
    for j:=1 to 3 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=4 to 6 do
    for j:=4 to 6 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=4 to 6 do
    for j:=4 to 6 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=4 to 6 do
    for j:=7 to 9 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=7 to 9 do
    for j:=1 to 3 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=7 to 9 do
    for j:=4 to 6 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    fillchar(b,sizeof(b),0);
    for i:=7 to 9 do
    for j:=7 to 9 do
    inc(b[a[i,j]]);
    for l:=1 to 9 do
    if b[l]=0 then p:=1;
    if p=1 then writeln('Wrong')
    else writeln('Right');
    end;
    readln;
    end.

  • 0
    @ 2015-11-05 18:46:16

    ###Pascal Code
    const z:array[1..9,1..9] of longint=((1,1,1,2,2,2,3,3,3),
    (1,1,1,2,2,2,3,3,3),
    (1,1,1,2,2,2,3,3,3),
    (4,4,4,5,5,5,6,6,6),
    (4,4,4,5,5,5,6,6,6),
    (4,4,4,5,5,5,6,6,6),
    (7,7,7,8,8,8,9,9,9),
    (7,7,7,8,8,8,9,9,9),
    (7,7,7,8,8,8,9,9,9));
    var map:array[1..9,1..9] of longint;
    hang,lie,ge:array[1..9,1..9] of boolean;
    i,j,k,n:longint;
    function cheak:boolean;
    var p,q:longint;
    begin
    for p:=1 to 9 do
    for q:=1 to 9 do
    if hang[p,q] or lie[p,q] or ge[p,q] then exit(false);
    exit(true);
    end;
    begin
    readln(n);
    for k:=1 to n do
    begin
    fillchar(hang,sizeof(hang),true);
    fillchar(lie,sizeof(lie),true);
    fillchar(ge,sizeof(ge),true);
    for i:=1 to 9 do
    for j:=1 to 9 do
    begin
    read(map[i,j]);
    hang[i,map[i,j]]:=false;
    lie[j,map[i,j]]:=false;
    ge[z[i,j],map[i,j]]:=false;
    end;
    if (not cheak) and (k<>n) then writeln('Wrong');
    if cheak and (k<>n) then writeln('Wrong');
    if (not cheak) and (k=n) then write('Wrong');
    if cheak and (k=n) then write('Right');
    end;
    end.

  • 0
    @ 2015-08-25 10:41:26

    const b:array[1..9,1..2] of longint=
    ((0,0),(1,0),(2,0),(0,1),(0,2),(1,1),(2,2),(1,2),(2,1));
    var
    f:array[0..9] of boolean;
    a:array[1..9,1..9] of longint;
    x,y,i,j,k,n:longint;
    flag:boolean;
    begin
    readln(n);
    for i:=1 to n do
    begin
    fillchar(a,sizeof(a),0);
    for j:=1 to 9 do
    begin
    for k:=1 to 9 do
    read(a[j,k]);readln;
    end;
    flag:=true;

    for j:=1 to 9 do
    begin
    fillchar(f,sizeof(f),false);
    for k:=1 to 9 do
    if f[a[j,k]]=false then f[a[j,k]]:=true
    else begin flag:=false;break;end;
    end;

    if flag then begin
    for j:=1 to 9 do
    begin
    fillchar(f,sizeof(f),false);
    for k:=1 to 9 do
    if f[a[k,j]]=false then f[a[k,j]]:=true
    else begin flag:=false;break; end;
    end; end;

    if flag then begin
    for j:=1 to 9 do
    begin
    fillchar(f,sizeof(f),false);
    case j mod 3 of
    0:y:=7; 1:y:=1; 2:y:=4;end;
    case j div 3 of
    0:x:=1; 1:x:=4; 3:x:=7;end;
    for k:=1 to 9 do
    if f[a[x+b[k,1],y+b[k,2]]]=false then f[a[x+b[k,1],y+b[k,2]]]:=true
    else begin flag:=false;break; end;
    end; end;

    if flag then writeln('Right') else writeln('Wrong');
    end;
    end.

  • 0
    @ 2015-08-09 17:10:36

    测试数据 #0: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #2: Accepted, time = 1 ms, mem = 800 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #4: Accepted, time = 1 ms, mem = 804 KiB, score = 10
    测试数据 #5: Accepted, time = 1 ms, mem = 800 KiB, score = 10
    测试数据 #6: Accepted, time = 2 ms, mem = 800 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 796 KiB, score = 10
    测试数据 #8: Accepted, time = 1 ms, mem = 804 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    Accepted, time = 21 ms, mem = 804 KiB, score = 100

    有点麻烦,思想很简单,一次ac

    program exam;
    const a:array[1..3] of longint=(1,4,7);
    b:array[1..3] of longint=(3,6,9);
    var i,j,m,n,k,l,t,h,o,x:longint;
    c:array[0..10000] of longint;
    v:boolean;
    f,g,s:array[1..9,1..9] of longint;
    procedure qt(k,l,r:longint);
    var x,y,m,p:longint;
    begin
    x:=l; y:=r;
    m:=f[k,(l+r) div 2];
    repeat
    while f[k,x]<m do inc(x);
    while f[k,y]>m do dec(y);
    if x<=y then
    begin
    p:=f[k,x]; f[k,x]:=f[k,y]; f[k,y]:=p;
    inc(x); dec(y);
    end;
    until x>y;
    if x<r then qt(k,x,r);
    if l<y then qt(k,l,y);
    end;

    procedure qt1(k,l,r:longint);
    var x,y,m,p:longint;
    begin
    x:=l; y:=r;
    m:=s[k,(l+r) div 2];
    repeat
    while s[k,x]<m do inc(x);
    while s[k,y]>m do dec(y);
    if x<=y then
    begin
    p:=s[k,x]; s[k,x]:=s[k,y]; s[k,y]:=p;
    inc(x); dec(y);
    end;
    until x>y;
    if x<r then qt1(k,x,r);
    if l<y then qt1(k,l,y);
    end;

    procedure qt2(l,r:longint);
    var i,j,m,p:longint;
    begin
    i:=l; j:=r;
    m:=c[(l+r) div 2];
    repeat
    while c[i]<m do inc(i);
    while c[j]>m do dec(j);
    if i<=j then
    begin
    p:=c[i]; c[i]:=c[j]; c[j]:=p;
    inc(i); dec(j);
    end;
    until i>j;
    if i<r then qt2(i,r);
    if l<j then qt2(l,j);
    end;

    begin
    readln(t);
    for h:=1 to t do
    begin
    v:=true;
    for i:=1 to 9 do
    begin
    for j:=1 to 9 do
    begin
    read(f[i,j]);
    g[i,j]:=f[i,j];
    end;
    readln;
    end;

    for i:=1 to 9 do
    begin
    qt(i,1,9);
    for j:=1 to 9 do
    if f[i,j]<>j then v:=false;
    end;

    if v=true then
    for i:=1 to 9 do
    begin
    for j:=1 to 9 do
    s[i,j]:=g[j,i];
    qt1(i,1,9);
    for j:=1 to 9 do
    if s[i,j]<>j then v:=false;
    end;

    if v=true then
    begin
    for i:=1 to 3 do
    for j:=1 to 3 do
    begin
    o:=0;
    for k:=a[i] to b[i] do
    for x:=a[j] to b[j] do
    begin
    inc(o);
    c[o]:=g[k,x];
    end;
    qt2(1,o);
    for k:=1 to o do
    if c[k]<>k then v:=false;
    end;
    end;
    if v=true then writeln('Right') else writeln('Wrong');
    end;
    end.

  • 0
    @ 2015-07-26 16:09:32

    P1335数独验证Accepted
    记录信息
    评测状态 Accepted
    题目 P1335 数独验证
    递交时间 2015-07-26 16:08:24
    代码语言 C++
    评测机 VijosEx
    消耗时间 30 ms
    消耗内存 280 KiB
    评测时间 2015-07-26 16:08:33
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 280 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 276 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 280 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 280 KiB, score = 10
    Accepted, time = 30 ms, mem = 280 KiB, score = 100
    代码
    #include <iostream>
    #include <stdio.h>
    #include <string.h>

    using namespace std;

    int n , m;
    int i , j , k;
    int a[10 + 2][10 + 2];
    bool is[10 + 2];
    int flag;
    int md;

    int main()
    {
    scanf( "%d" , &n );
    for( i = 1 ; i <= n ; i++ )
    {
    flag = 0;
    md = 0;
    for( j = 1 ; j <= 9 ; j++ )
    for( k = 1 ; k <= 9 ; k++ )
    scanf( "%d" , &a[j][k] );
    for( j = 1 ; j <= 9 ; j++ )
    {
    memset( is , 0, sizeof( is ) );
    for( k = 1 ; k <= 9 ; k++ )
    is[ a[j][k] ] = 1;
    flag = 0;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[ k ] )
    {
    flag = 1;
    break;
    }

    }
    if( flag )
    {
    cout << "Wrong\n";
    continue;
    }

    for( j = 1 ; j <= 9 ; j++ )
    {
    memset( is , 0, sizeof( is ) );
    for( k = 1 ; k <= 9 ; k++ )
    is[ a[k][j] ] = 1;
    flag = 0;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[ k ] )
    {
    flag = 1;
    break;
    }

    }
    if( flag )
    {
    cout << "Wrong\n";
    continue;

    }

    if( md )
    continue;
    memset( is , 0, sizeof( is ) );
    for( j = 1 ; j <= 3 ; j++ )
    for( k = 1 ; k <= 3 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    memset( is , 0, sizeof( is ) );
    for( j = 4 ; j <= 6 ; j++ )
    for( k = 1 ; k <= 3 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    for( j = 7 ; j <= 9 ; j++ )
    for( k = 1 ; k <= 3 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    for( j = 1 ; j <= 3 ; j++ )
    for( k = 4 ; k <= 6 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    for( j = 4 ; j <= 6 ; j++ )
    for( k = 4 ; k <= 6 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    for( j = 7 ; j <= 9 ; j++ )
    for( k = 4 ; k <= 6 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    for( j = 1 ; j <= 3 ; j++ )
    for( k = 7 ; k <= 9 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    for( j = 4 ; j <= 6 ; j++ )
    for( k = 7 ; k <= 9 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    for( j = 7 ; j <= 9 ; j++ )
    for( k = 7 ; k <= 9 ; k++ )
    is[ a[j][k] ] = 1;
    for( k = 1 ; k <= 9 ; k++ )
    if( !is[k] )
    flag = 1;
    if( flag )
    {
    md = 1;
    cout << "Wrong" << endl;
    continue;
    }
    cout << "Right"<< endl;
    }
    return 0;
    }

  • 0
    @ 2015-07-18 11:19:23

    #include<iostream>
    using namespace std;
    int sudoko[20][9][9];
    bool check[10];
    bool test(int a)
    {
    for(int i=0;i<9;i++)
    {
    for(int j=0;j<10;j++)
    check[j]=false;
    for(int j=0;j<9;j++)
    if(check[sudoko[a][i][j]])return false;
    else check[sudoko[a][i][j]]=true;
    }
    for(int i=0;i<9;i++)
    {
    for(int j=0;j<10;j++)
    check[j]=false;
    for(int j=0;j<9;j++)
    if(check[sudoko[a][j][i]])return false;
    else check[sudoko[a][j][i]]=true;
    }
    for(int i1=0;i1<9;i1+=3)
    for(int i2=0;i2<9;i2+=3)
    {
    for(int j=0;j<10;j++)
    check[j]=false;
    for(int j1=i1;j1<i1+3;j1++)
    for(int j2=i2;j2<i2+3;j2++)
    if(check[sudoko[a][j1][j2]])return false;
    else check[sudoko[a][j1][j2]]=true;
    }
    return true;
    }
    int main()
    {
    bool first=true;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    for(int j=0;j<9;j++)
    for(int k=0;k<9;k++)
    cin>>sudoko[i][j][k];
    for(int i=0;i<n;i++)
    {
    if(first==true)first=false;
    else cout<<endl;
    if(test(i))cout<<"Right";
    else cout<<"Wrong";
    }
    return 0;
    }

  • 0
    @ 2015-06-27 17:20:28

    暴力模拟
    ###C++ Code
    #include <iostream>
    #include <set>
    using namespace std;
    int map[10][10];

    bool Sq_C(int x,int y)
    {
    set<int> temp;
    for(int i=x;i<=x+2;i++)
    {
    for(int j=y;j<=y+2;j++)
    {
    temp.insert(map[i][j]);
    }
    }
    return temp.size()==9;
    }

    bool J_XY()
    {
    bool answer=1;
    set<int> temp1,temp2;
    for(int i=1;i<=9;i++)
    {
    temp1.clear();
    temp2.clear();
    for(int j=1;j<=9;j++)
    {
    temp1.insert(map[i][j]);
    temp2.insert(map[j][i]);
    }
    if(!((temp1.size()==9)&&(temp2.size()==9)))answer=false;
    }
    return answer;
    }

    bool J_Sq()
    {
    bool ans=1;
    for(int i=1;i<=9;i+=3)
    {
    for(int j=1;j<=9;j+=3)
    {
    if(!Sq_C(i,j))
    {
    ans=false;
    break;
    }
    }
    if(!ans)break;
    }
    return ans;
    }

    void J()
    {
    for(int x=1;x<=9;x++)
    {
    for(int y=1;y<=9;y++)
    {
    cin>>map[x][y];
    }
    }
    if(J_Sq()&&J_XY())
    {
    cout<<"Right\n";
    }
    else
    {
    cout<<"Wrong\n";
    }
    }

    int main()
    {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    J();
    }
    return 0;
    }

  • 0
    @ 2015-03-05 14:41:02

    暴力模拟,实现细节见代码。

    Pascal Code

    type
    hash=array[1..9] of boolean;
    var
    a:array[1..9,1..9] of longint;
    r,c,b:array[1..9] of hash;
    i,j,n,k:longint;
    flag:boolean; //当前数独是否不符合要求
    function getbn(i,j:longint):longint; //返回位于第几个3*3正方形
    begin
    exit((i-1) div 3*3+(j-1) div 3+1);
    end;

    begin
    readln(n);
    for i:=1 to n do
    begin
    flag:=false;
    fillchar(r,sizeof(r),0);
    fillchar(c,sizeof(c),0);
    fillchar(b,sizeof(b),0);
    for j:=1 to 9 do
    begin
    for k:=1 to 9 do
    read(a[j,k]);
    readln;
    end;
    if i<>n then readln;
    for j:=1 to 9 do
    begin
    for k:=1 to 9 do
    begin
    if r[j,a[j,k]] or c[k,a[j,k]] or b[getbn(j,k),a[j,k]]
    then begin
    flag:=true;
    break;
    end;
    r[j,a[j,k]]:=true;
    c[k,a[j,k]]:=true;
    b[getbn(j,k),a[j,k]]:=true;
    end;
    if flag then break;
    end;
    if flag then writeln('Wrong')
    else writeln('Right');
    end;
    end.

  • 0
    @ 2014-07-07 22:12:11

    #block
    var
    i,j,k,l,m,n:longint;
    b:boolean;
    a:array[1..9,1..9] of longint;
    v:array[1..9] of longint;
    begin
    readln(n);
    for i:=1 to n do
    begin
    b:=true;
    for j:=1 to 9 do
    for k:=1 to 9 do
    read(a[j][k]);

    for j:=1 to 9 do
    begin
    if b=false then break;
    fillchar(v,sizeof(v),0);
    for k:=1 to 9 do
    begin
    if v[a[j][k]]=1 then
    begin
    writeln('Wrong');
    b:=false;
    break;
    end
    else inc(v[a[j][k]]);
    end;
    end;

    if b=true then
    for j:=1 to 9 do
    begin
    if b=false then break;
    fillchar(v,sizeof(v),0);
    for k:=1 to 9 do
    if v[a[k][j]]=1 then
    begin
    b:=false;
    writeln('Wrong');
    break;
    end
    else inc(v[a[k][j]])
    end;
    if b=true then
    begin
    for j:=1 to 3 do
    for k:=1 to 3 do
    begin
    fillchar(v,sizeof(v),0);
    for l:=(j*3-2) to j*3 do
    begin
    if b=false then break;
    for m:=(k*3-2) to k*3 do
    if v[a[l][m]]=1 then
    begin
    writeln('Wrong');
    b:=false;
    break;
    end
    else inc(v[a[l][m]]);
    end;
    end;
    end;
    if b=true then writeln('Right');
    end;
    end.

  • 0
    @ 2013-11-02 14:55:18

    暴搜通过、、水题

    var fin:text;
    i,j,k,n,l:longint;
    ans:boolean;
    qipan:array[1..9,1..9] of byte;
    flag:array[1..9] of boolean;
    begin
    assign(fin,'shudu.in');reset(fin);
    readln(fin,n);
    for l:=1 to n do begin
    for j:=1 to 9 do begin
    for k:=1 to 9 do read(fin,qipan[j,k]);
    readln(fin);
    end;
    ans:=false;
    for i:=1 to 9 do begin
    fillchar(flag,sizeof(flag),false);
    for j:=1 to 9 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;
    end;
    for i:=1 to 9 do begin
    fillchar(flag,sizeof(flag),false);
    for j:=1 to 9 do if not flag[qipan[j,i]] then flag[qipan[j,i]]:=true else ans:=true;
    end;

    fillchar(flag,sizeof(flag),false);
    for i:=1 to 3 do
    for j:=1 to 3 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    fillchar(flag,sizeof(flag),false);
    for i:=1 to 3 do
    for j:=4 to 6 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    fillchar(flag,sizeof(flag),false);
    for i:=1 to 3 do
    for j:=7 to 9 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    fillchar(flag,sizeof(flag),false);
    for i:=4 to 6 do
    for j:=1 to 3 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    fillchar(flag,sizeof(flag),false);
    for i:=4 to 6 do
    for j:=4 to 6 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    fillchar(flag,sizeof(flag),false);
    for i:=4 to 6 do
    for j:=7 to 9 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    fillchar(flag,sizeof(flag),false);
    for i:=7 to 9 do
    for j:=1 to 3 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    fillchar(flag,sizeof(flag),false);
    for i:=7 to 9 do
    for j:=4 to 6 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    fillchar(flag,sizeof(flag),false);
    for i:=7 to 9 do
    for j:=7 to 9 do if not flag[qipan[i,j]] then flag[qipan[i,j]]:=true else ans:=true;

    if ans then writeln('Wrong') else writeln('Right');

    end;
    end.

  • 0
    @ 2013-10-30 22:10:23

    var i,j,k,l,m,n:Longint;
    A:array[1..9,1..9] of Longint;

    Function Check:String;
    var i,j,k,L:Longint;
    Bo:array[1..9] of Boolean;
    Begin
    For i:=1 to 9 do
    Begin
    Fillchar(Bo,sizeof(Bo),False);
    For j:=1 to 9 do
    Begin
    If Bo[A[i,j]] then Exit('Wrong');
    Bo[A[i,j]]:=True;
    End;
    End;
    For i:=1 to 9 do
    Begin
    Fillchar(Bo,sizeof(Bo),False);
    For j:=1 to 9 do
    Begin
    If Bo[A[j,i]] then Exit('Wrong');
    Bo[A[j,i]]:=True;
    End;
    End;
    For i:=1 to 3 do
    For j:=1 to 3 do
    Begin
    Fillchar(Bo,sizeof(Bo),False);
    For k:=3*(i-1)+1 to 3*i do
    For L:=3*(j-1)+1 to 3*j do
    Begin
    If Bo[A[K,L]] then Exit('Wrong');
    Bo[A[K,L]]:=True;
    End;
    End;
    Exit('Right');
    End;

    Begin
    Readln(N);
    For i:=1 to N do
    Begin
    For j:=1 to 9 do
    For k:=1 to 9 do Read(A[j,k]);
    Writeln(Check);
    End;
    End.

  • 0
    @ 2013-10-08 12:32:31

    简单题吧,算个总和算个总积就行。理论上好像存在一定漏洞,不过数据很弱。59行AC。
    C++ Code:
    #include<iostream>
    using namespace std;
    int main(){
    int cases;
    cin>>cases;
    for(int i=0;i<cases;i++){
    bool ans = true;
    int a[9][9];
    for(int j=0;j<9;j++){
    for(int k=0;k<9;k++){
    cin>>a[j][k];
    }
    }

    for(int j=0;j<9;j++){
    int sum =0;
    int mult=1;
    for(int k=0;k<9;k++){
    sum+=a[j][k];
    mult*=a[j][k];
    }
    if(sum!=45||mult!=362880){
    ans=false;
    break;
    }
    }//横排判断

    for(int j=0;j<9;j++){
    int sum =0;
    int mult=1;
    for(int k=0;k<9;k++){
    sum+=a[k][j];
    mult*=a[k][j];
    }
    if(sum!=45||mult!=362880){
    ans=false;
    break;
    }
    }//竖排判断

    for(int j=0;j<7;j+=3){
    for(int k=0;k<7;k+=3){
    int sum=a[j][k]+a[j][k+1]+a[j][k+2]+a[j+1][k]+a[j+1][k+1]+a[j+1][k+2]+a[j+2][k]+a[j+2][k+1]+a[j+2][k+2];
    int mult=a[j][k]*a[j][k+1]*a[j][k+2]*a[j+1][k]*a[j+1][k+1]*a[j+1][k+2]*a[j+2][k]*a[j+2][k+1]*a[j+2][k+2];
    if(sum!=45||mult!=362880){
    ans=false;
    break;
    }
    }
    }
    //3x3判断
    if(ans==true){
    cout<<"Right"<<endl;
    } else{
    cout<<"Wrong"<<endl;
    }

    }
    }

信息

ID
1335
难度
4
分类
模拟 点击显示
标签
递交数
5131
已通过
1978
通过率
39%
被复制
20
上传者