题解

205 条题解

  • 0
    @ 2017-05-06 14:53:04
    #include<stdio.h>
    int b[10][10];
    int panduan()
    {
        int t[10]={0};
        int w=1;
        for(int h=1;h<=9;h++)
        {
            t[b[h][1]]=b[h][1];
            t[b[h][2]]=b[h][2];
            t[b[h][3]]=b[h][3];
            t[b[h][4]]=b[h][4];
            t[b[h][5]]=b[h][5];
            t[b[h][6]]=b[h][6];
            t[b[h][7]]=b[h][7];
            t[b[h][8]]=b[h][8];
            t[b[h][9]]=b[h][9];
            for(int i=1;i<=9;i++)
            {
                if(t[i]==0)
                return 0;
            }
        }
        for(int c=1;c<=9;c++)
        {
            t[c]=0;
        }
        for(int l=1;l<=9;l++)
        {
            for(int c=0;c<=9;c++)
            {
                t[c]=0;
            }
            t[b[1][l]]=b[1][l];
            t[b[2][l]]=b[2][l];
            t[b[3][l]]=b[3][l];
            t[b[4][l]]=b[4][l];
            t[b[5][l]]=b[5][l];
            t[b[6][l]]=b[6][l];
            t[b[7][l]]=b[7][l];
            t[b[8][l]]=b[8][l];
            t[b[9][l]]=b[9][l];
            for(int m=1;m<=9;m++)
            {
                if(t[m]==0)
                   return 0;
            }
        }
        for(int c=1;c<=9;c++)
        {
            t[c]=0;
        }
        for(int h=1;h<=6;h+=3)
            {
                for(int c=1;c<=9;c++)
                {
                    t[c]=0;
                }
                for(int l=1;l<=6;l+=3)
                {
                    t[b[h][l]]=b[h][l];
                    t[b[h][l+1]]=b[h][l+1];
                    t[b[h][l+2]]=b[h][l+2];
                    t[b[h+1][l]]=b[h][l];
                    t[b[h+1][l+1]]=b[h][l+1];
                    t[b[h+1][l+2]]=b[h][l+2];
                    t[b[h+2][l]]=b[h][l];
                    t[b[h+2][l+1]]=b[h][l+1];
                    t[b[h+2][l+2]]=b[h][l+2];
                }
            }
            for(int r=1;r<=9;r++)
            {
                if(t[r]==0)
                return 0;
            }
        return 1;
    }
    int main()
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            for(int h=1;h<=9;h++)
            {
                for(int l=1;l<=9;l++)
                {
                    scanf("%d",&b[h][l]);
                }
            }
            if(panduan())
               printf("Right\n");
            else
               printf("Wrong\n");
        }   
    }
    
  • 0
    @ 2017-05-01 11:18:55
    #include<stdio.h>
    int main()
    {
        int a[9][9];                          //用来将每个小数独排成一行 ,一共有9行 
        int t;
        int counts, num[9][9], i, j, m, k, judge;
        scanf("%d", &counts);
        for (m = 0; m < counts; m++)        //循环输入counts个数独
        {
            judge = 1;                     //默认这个数独是正确的,记为1
            for (i = 0; i < 9; i++)        //输入数独,二维数组
                for (j = 0; j < 9; j++)
                    scanf("%d", &num[i][j]);
                                       //   printf("\n");不应该要这个...话说不是说好的有换行吗...
    
            for (i = 0; i < 9; i++)           //判断行的情况
            {
                for (j = 0; j < 8; j++)
                {
                    for (k = j + 1; k < 9; k++)
                        if (num[i][j] == num[i][k])
                        {
                            printf("Wrong\n");
                            judge = 0;
                            break;
                        }
                    if (judge == 0)break;
                }
                if (judge == 0)break;
            }
            if (judge == 0)continue;
    
            for (j = 0; j < 9; j++)                   //判断列的情况
            {
                for (i = 0; i < 8; i++)
                {
                    for (k = i + 1; k < 9; k++)
                        if (num[i][j] == num[k][j])
                        {
                            printf("Wrong\n");
                            judge = 0;
                            break;
                        }
                    if (judge == 0)break;
                }
                if (judge == 0)break;
            }
            if (judge == 0)continue;
    
            t = 0;
            for (i = 0; i < 9; i = i + 3)
                for (j = 0; j < 9; j = j + 3)
                {
                    a[t][0] = num[i][j], a[t][1] = num[i][j + 1], a[t][2] = num[i][j + 2], a[t][3] = num[i + 1][j], a[t][4] = num[i + 1][j + 1], a[t][5] = num[i + 1][j + 2], a[t][6] = num[i + 2][j],
                        a[t][7] = num[i + 2][j + 1], a[t][8] = num[i + 2][j + 2];    //对每一个小数独进行重组
                    t++;
                }
            for (i = 0; i < 9; i++)           //判断重组后的数独情况
            {
                for (j = 0; j < 8; j++)
                {
                    for (k = j + 1; k < 9; k++)
                        if (a[i][j] == a[i][k])
                        {
                            printf("Wrong\n");
                            judge = 0;
                            break;
                        }
                    if (judge == 0)break;
                }
                if (judge == 0)break;
            }
            if (judge == 0)continue;
            if (judge == 1) printf("Right\n");
        }
        getchar();
        getchar();
        return 0;
    }
    
    
  • 0
    @ 2017-04-30 14:11:07

    暴力

    //2017年4月30日13:18:37
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    int a[10][10];
    int b[10];
    int n;
    int h;
    int main(){
        cin >> n;
    sign:while(n != 0){
            for(int i=1;i<=9;i++)
                for(int j=1;j<=9;j++)
                    cin >> a[i][j];
            for(int i=1;i<=9;i++){
                memset(b, 0, sizeof(b));
                for(int j=1;j<=9;j++){
                    if(b[a[i][j]] == 0)
                        b[a[i][j]] = 1;
                    else{
                        cout << "Wrong" << endl;
                        n--;
                        goto sign;
                    }
                    if(j == 9)
                        memset(b, 0, sizeof(b));
                }
            }
            for(int i=1;i<=9;i++){
                memset(b, 0, sizeof(b));
                for(int j=1;j<=9;j++){
                    if(b[a[j][i]] == 0)
                        b[a[j][i]] = 1;
                    else{
                        cout << "Wrong" << endl;
                        n--;
                        goto sign;
                    }
                }
            }
            memset(b, 0, sizeof(b));
            for(int k=1;k<=9;k+=3){
                memset(b, 0, sizeof(b)); 
                for(int i=k;i<k+3;i++){
                    for(int j=1;j<=3;j++){
                        if(b[a[i][j]] == 0)
                            b[a[i][j]] = 1;
                        else{
                            cout << "Wrong" << endl;
                            n--;
                            goto sign;
                        }
                    }
                }
                memset(b, 0, sizeof(b));
                    for(int i=k;i<k+3;i++)
                    for(int j=4;j<=6;j++){
                        if(b[a[i][j]] == 0) 
                            b[a[i][j]] = 1;
                        else{
                            cout << "Wrong" << endl;
                            n--;
                            goto sign;
                        }
                    }
                memset(b, 0, sizeof(b));
                    for(int i=k;i<k+3;i++)
                    for(int j=7;j<=9;j++){
                        if(b[a[i][j]] == 0) 
                            b[a[i][j]] = 1;
                        else{
                            cout << "Wrong" << endl;
                            n--;
                            goto sign;
                        }
                    }
            
            }
                        
            cout << "Right" << endl;
            n--;
        }
    
        return 0;
    }
    
  • 0
    @ 2017-04-07 16:54:45

    模拟问题
    1. 判断行和列
    2. 判断九宫格

    #include <iostream>
    #include <set>
    using namespace std;
    
    int main() {
        int t;
        cin >> t;
        while (t--) {
            int a[9][9];
            for (int i = 0; i < 9; i++)
                for (int j = 0; j < 9; j++)
                    cin >> a[i][j];
            bool right = true;
            set<int> my_set;
            for (int i = 0; i < 9; i++) {
                my_set.clear();
                for (int j = 0; j < 9; j++)
                    my_set.insert(a[i][j]);
                if (my_set.size() != 9) {
                    right = false;
                    goto output;
                }
                my_set.clear();
                for (int j = 0; j < 9; j++)
                    my_set.insert(a[j][i]);
                if (my_set.size() != 9) {
                    right = false;
                    goto output;
                }
            }
            for (int i = 0; i < 9; i += 3)
                for (int j = 0; j < 9; j += 3) {
                    my_set.clear();
                    for (int m = i; m <= i + 2; m++)
                        for (int n = j; n <= j + 2; n++)
                            my_set.insert(a[m][n]);
                    if (my_set.size() != 9) {
                        right = false;
                        goto output;
                    }
                }
            output:
            if (right)
                cout << "Right" << endl;
            else
                cout << "Wrong" << endl;
        }
        return 0;
    }
    
  • 0
    @ 2017-02-07 22:55:45

    var
    a:array[1..9,1..9]of longint;
    f:array[1..9]of boolean;
    i,j,k,l,m,n:longint;
    rw:boolean;
    begin
    readln(n);
    for i:=1 to n do
    begin
    rw:=true;
    for j:=1 to 9 do
    for k:=1 to 9 do
    read(a[j,k]);
    for j:=1 to 9 do
    begin
    fillchar(f,sizeof(f),false);
    for k:=1 to 9 do
    f[a[j,k]]:=true;
    for k:=1 to 9 do
    if f[k]=false then begin
    writeln('Wrong');
    rw:=false;
    break;
    end;
    if rw=false then break;
    fillchar(f,sizeof(f),false);
    for k:=1 to 9 do
    f[a[k,j]]:=true;
    for k:=1 to 9 do
    if f[k]=false then begin
    writeln('Wrong');
    rw:=false;
    break;
    end;
    if rw=false then break;
    end;
    if rw=false then continue;
    for j:=0 to 2 do
    begin
    for k:=0 to 2 do
    begin
    fillchar(f,sizeof(f),false);
    for l:=1 to 3 do
    for m:=1 to 3 do
    f[a[j*3+l,k*3+m]]:=true;
    for l:=1 to 9 do
    if f[l]=false then begin
    writeln('Wrong');
    rw:=false;
    break;
    end;
    if rw=false then break;
    end;
    if rw=false then break;
    end;
    if rw=false then continue;
    writeln('Right');
    end;
    end.
    //第150题纪念

  • 0
    @ 2016-11-26 09:56:30

    #include<cstdio>
    #include<cstring>
    #define N 10
    int a[N][N];//魔方
    int h[N][N],l[N][N],t[N][N];//行、列、3*3小方格里各数是否存在
    int main()
    {
    int i,j,n,k,flag;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {flag=0;
    memset(h,0,sizeof(h));
    memset(l,0,sizeof(h));
    memset(t,0,sizeof(h));
    for(j=1;j<=9;j++)
    for(k=1;k<=9;k++)
    scanf("%d",&a[j][k]);
    for(j=1;j<=9;j++)
    {
    for(k=1;k<=9;k++)
    {//行
    if(h[j][a[j][k]]!=0) {flag=1;break;}
    h[j][a[j][k]]=1;
    //列
    if(l[j][a[j][k]]!=0) {flag=1;break;}
    l[j][a[j][k]]=1;
    //3*3
    if(t[(j-1)/3*3+(k+2)/3][a[j][k]]!=0) {flag=1;break;}
    t[(j-1)/3*3+(k+2)/3][a[j][k]]=1;
    }
    if(flag==1) break;
    }
    if(flag==0) printf("Right\n");
    else printf("Wrong\n");

    }
    return 0;
    }

  • 0
    @ 2016-11-25 02:25:04
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <climits>  
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <queue>
    
    using namespace std;
    
    
    int main()
    {
      int n;
      cin>>n;
    
      set<int> ss;                 //用set读入  set.size!=9 就是错的
    
      int a[9][9];
      memset(a,0,sizeof(a));
    
      next:
      while(n>0)
      {
        for(int i=0; i<=8; i++)
          for(int j=0; j<=8; j++)
            {cin>>a[i][j];}
    
     
        for(int i=0; i<=8; i++)
         {
          for(int j=0; j<=8; j++)
          {
            ss.insert(a[i][j]);
          }
          if(ss.size()!=9){cout<<"Wrong"<<endl;n--;goto next;}
         }
         ss.clear();                               //横的
          
         for(int i=0; i<=8; i++)
         {
          for(int j=0; j<=8; j++)
          {
            ss.insert(a[j][i]);
          }
          if(ss.size()!=9){cout<<"Wrong"<<endl;n--;goto next;}
         }
         ss.clear();                                //竖的
    
    
         for(int k=0;k<=2;k++)
         {
          for(int uu=0;uu<=2;uu++)
          {
            for(int i=3*k;i<=3*k+2;i++)
              for(int j=3*uu;j<=3*uu+2;j++)
                {ss.insert(a[i][j]);}
    
            if(ss.size()!=9){cout<<"Wrong"<<endl;n--;goto next;}
            ss.clear();
          }
         }                                       //九宫格  
         
         ss.clear();
         cout<<"Right"<<endl;
         n--;
      }
    
    
      return 0;
    }
    
  • 0
    @ 2016-11-20 21:25:33
    var n,k,i,j:longint;
        a:array[1..9,1..9]of longint;
        b:array[0..9]of longint;
    function findjiugongge:boolean;
    var i,j,k,l,start,finish,q:longint;
    begin
      findjiugongge:=true;
      for i:=1 to 3 do 
        begin
          k:=0;
          for j:=1 to 3 do
            begin
              fillchar(b,sizeof(b),0);
              k:=k+1;
              start:=(k-1)*3+1;
              finish:=(i-1)*3+1;
              for q:=start to start+2 do
                for l:=finish to finish+2 do 
                  b[a[l,q]]:=b[a[l,q]]+1;
              for q:=1 to 9 do
              if b[q]>1
              then begin
                     findjiugongge:=false;
                     exit;
                   end;   
             end;
        end;             
    end;
    function findlie:boolean;
    var i,j:longint;
    begin
      findlie:=true;
      for i:=1 to 9 do
        begin
          fillchar(b,sizeof(b),0);
          for j:=1 to 9 do 
            b[a[j,i]]:=b[a[j,i]]+1;
          for j:=1 to 9 do
            if b[j]>1
            then begin
                   findlie:=false;
                   exit;
                 end;
        end;           
    end;
    function findhang:boolean;
    var i,j:longint;
    begin
      findhang:=true;
      for i:=1 to 9 do
        begin
          fillchar(b,sizeof(b),0);
          for j:=1 to 9 do 
            b[a[i,j]]:=b[a[i,j]]+1;
          for j:=1 to 9 do
            if b[j]>1
            then begin
                   findhang:=false;
                   exit;
                 end;
        end;           
    end;
    begin
      readln(n);
      for k:=1 to n do 
        begin
          for i:=1 to 9 do 
            for j:=1 to 9 do
              read(a[i,j]);
          if not findhang
          then begin
                 writeln('Wrong') ;
                 continue;
               end;
          if not findlie
          then begin
                 writeln('Wrong');
                 continue;
               end;
          if not findjiugongge
          then begin
                 writeln('Wrong');
                 continue;
               end;
          writeln('Right');     
         end;         
    end.
    
    • @ 2017-01-20 18:27:06

      来打个酱油,马上走:
      var
      n,max,i,j,x:longint;
      space,ch:char;
      a,b,c:array[1..9,1..9] of boolean;
      f:boolean;
      begin
      readln(n);
      for max:=1 to n do
      begin
      for i:=1 to 9 do
      for j:=1 to 9 do
      begin
      a[i,j]:=false;
      b[i,j]:=false;
      c[i,j]:=false;
      end;
      f:=true;
      for i:=1 to 9 do
      begin
      for j:=1 to 9 do
      begin
      read(ch);
      x:=ord(ch)-ord('0');
      if j<>9 then
      read(space);
      if f then
      begin
      if a[i,x] then
      f:=false
      else
      a[i,x]:=true;
      if b[j,x] then
      f:=false
      else
      b[j,x]:=true;
      if c[((i+2) div 3-1)*3+(j+2) div 3,x] then
      f:=false
      else
      c[((i+2) div 3-1)*3+(j+2) div 3,x]:=true;
      end;
      end;
      readln;
      end;
      if f then
      writeln('Right')
      else
      writeln('Wrong');
      if max<>n then readln;
      end;
      end.

  • 0
    @ 2016-11-18 14:35:07

    水题
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    int a[10][10];
    int main(){
    int i,j,k,n,m;
    scanf("%d",&n);
    for(int o=1;o<=n;o++){
    for(i=1;i<=9;i++)
    for(j=1;j<=9;j++)
    scanf("%d",&a[i][j]);
    int lala=0;
    int flag[10];
    for(i=1;i<=9;i++){
    memset(flag,0,sizeof(flag));
    for(j=1;j<=9;j++)
    flag[a[i][j]]=1;
    int f=0;
    for(j=1;j<=9;j++)
    if(!flag[j])f=1;
    if(f)lala=1;
    }
    if(lala){
    printf("Wrong\n");continue;
    }
    lala=0;
    for(i=1;i<=9;i+=3){
    flag[a[i][1]]=1;
    flag[a[i][2]]=1;
    flag[a[i][3]]=1;
    flag[a[i+1][1]]=1;
    flag[a[i+1][2]]=1;
    flag[a[i+1][3]]=1;
    flag[a[i+2][1]]=1;
    flag[a[i+2][2]]=1;
    flag[a[i+2][3]]=1;
    for(j=1;j<=9;j++)
    if(!flag[j])lala=1;
    if(lala)break;
    memset(flag,0,sizeof(flag));
    flag[a[i][4]]=1;
    flag[a[i][5]]=1;
    flag[a[i][6]]=1;
    flag[a[i+1][4]]=1;
    flag[a[i+1][5]]=1;
    flag[a[i+1][6]]=1;
    flag[a[i+2][4]]=1;
    flag[a[i+2][5]]=1;
    flag[a[i+2][6]]=1;
    for(j=1;j<=9;j++)
    if(!flag[j])lala=1;
    if(lala)break;
    memset(flag,0,sizeof(flag));
    flag[a[i][7]]=1;
    flag[a[i][8]]=1;
    flag[a[i][9]]=1;
    flag[a[i+1][7]]=1;
    flag[a[i+1][8]]=1;
    flag[a[i+1][9]]=1;
    flag[a[i+2][7]]=1;
    flag[a[i+2][8]]=1;
    flag[a[i+2][9]]=1;
    for(j=1;j<=9;j++)
    if(!flag[j])lala=1;
    if(lala)break;
    }
    if(lala)printf("Wrong\n");
    else printf("Right\n");
    }
    return 0;
    }

  • 0
    @ 2016-10-22 11:44:25

    又错了三次,坑我呢;
    不就是边输入边输出吗;
    后来开了个数组记录正确和错误用来输入完以后输出;
    顺便知道了#5,#6都只有一个要验证的独数,嘿嘿;

    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    #include <cstring>
    #include <algorithm>
    #include <vector>

    using namespace std;

    int a[9][9];
    int num;
    int ans[1005], m;

    void init()
    {

    for( int i = 0; i < 9; i++)
    for( int j = 0; j < 9; j++)
    cin >> a[i][j];
    }

    void ch()
    {
    int book[10];
    for( int i = 0; i < 9; i++){

    memset(book,0, sizeof(book));
    for( int j = 0; j < 9; j++){

    if(book[a[i][j]] == 0)
    book[a[i][j]] = 1;
    else{
    ans[m ++] = 1;
    return;
    }
    }

    }

    for( int i = 0; i < 9; i++){
    memset(book,0, sizeof(book));
    for( int j = 0; j < 9; j++){

    if(book[a[j][i]] == 0)
    book[a[j][i]] = 1;
    else{
    ans[m ++] = 1;
    return;
    }

    }
    }

    for ( int i = 0; i <= 6; i += 3)
    for( int j = 0; j <= 6; j += 3)
    {

    memset(book,0, sizeof(book));

    for( int k = 0; k < 3; k ++)
    for( int l = 0; l < 3; l ++){

    if( book[a[i + k][j + l]] == 0)
    book[a[i + k][j + l]] = 1;
    else{

    ans[m ++] = 1;
    return;
    }
    }
    }

    ans[m ++] = 0;

    }

    int main()
    {

    cin >> num;
    for(int i = 0; i < num; i++){

    init();
    ch();
    }

    for( int i = 0; i < num; i++)
    if( ans[i] == 1)
    cout << "Wrong" << endl;
    else
    cout << "Right" << endl;

    }

  • 0
    @ 2016-10-09 01:36:41

    读错题了,所以写了一个不知道n的程序,还挺有意思的。
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <vector>
    #include <cstdio>

    using namespace std;

    int num[9][9]; //数独数据
    vector <string> ans; //结果

    inline bool readin() //输入数独数据,有输入返回true,没有返回false
    {
    int i, j;
    bool a = false;
    for (i = 0; i < 9; ++i)
    for (j = 0; j < 9; ++j)
    if (cin >> num[i][j])a = true;
    return a;
    }

    inline bool opdr() //判断是否符合数独规则,符合符合true,不符合符合false
    {
    int i, j;
    int n, m;
    bool lnum[10];
    for (i = 0; i < 9; ++i) //判断行
    {
    memset(lnum, 0, sizeof(lnum));
    for (j = 0; j < 9; ++j)
    if (!lnum[num[i][j]])lnum[num[i][j]] = true;
    else return false;
    }
    for (j = 0; j < 9; ++j) //判断列
    {
    memset(lnum, 0, sizeof(lnum));
    for (i = 0; i < 9; ++i)
    if (!lnum[num[i][j]])lnum[num[i][j]] = true;
    else return false;
    }
    for (n = 0; n < 9; n+=3) //判断九宫格
    {
    for (m = 0; m < 9; m+=3)
    {
    memset(lnum, 0, sizeof(lnum));
    for (i = n; i < n + 3; ++i)
    {
    for (j = m; j < m + 3; ++j)
    if (!lnum[num[i][j]])lnum[num[i][j]] = true;
    else return false;
    }
    }
    }
    return true;
    }

    inline void rout() //输出结果
    {
    int len = ans.size();
    int i;
    for (i = 0; i < len; ++i)
    cout << ans[i] << endl;
    }

    int main()
    {
    getchar(); //读错题了,所以忽略第一个数字
    while (readin()) //有输入就循环,没有就不循环
    if (opdr())ans.push_back("Right"); //判断是否合法
    else ans.push_back("Wrong");
    rout();
    return 0;
    }

  • 0
    @ 2016-10-03 14:34:39

    调试了半天……最后发现有个i打成j了……被自己坑了……
    ```pascal
    program P1335;
    var
    x,y,i,j,n,k:integer;
    a:array[1..9,1..9] of integer;
    b:array[1..9] of boolean;
    bool:boolean;
    begin
    readln(n);
    for k:=1 to n do
    begin
    for i:=1 to 9 do
    for j:=1 to 9 do
    read(a[i,j]);
    if k<>n
    then readln;
    bool:=true;
    if bool then
    begin
    for i:=1 to 9 do
    begin
    if bool then
    begin
    for j:=1 to 9 do
    b[j]:=false;
    for j:=1 to 9 do
    if not(b[a[i,j]])
    then b[a[i,j]]:=true
    else
    begin
    bool:=false;
    break;
    end;;
    end;
    end;
    end;
    if bool then
    begin
    for j:=1 to 9 do
    begin
    if bool then
    begin
    for i:=1 to 9 do
    b[i]:=false;
    for i:=1 to 9 do
    if not(b[a[i,j]])
    then b[a[i,j]]:=true
    else
    begin
    bool:=false;
    break;
    end;
    end;
    end;
    end;
    if bool then
    begin
    for x:=0 to 2 do
    for y:=0 to 2 do
    begin
    if bool then
    begin
    for i:=1 to 9 do
    b[i]:=false;
    for i:=1+3*x to 3+3*x do
    for j:=1+3*y to 3+3*y do
    if not(b[a[i,j]])
    then b[a[i,j]]:=true
    else
    begin
    bool:=false;
    break;
    end;
    end;
    end;
    end;
    if bool
    then writeln('Right')
    else writeln('Wrong');
    end;
    end.

    有点复杂,但纯模拟好理解一点
    
  • 0
    @ 2016-08-31 09:25:58

    U41君来刷水题了!
    ```Pascal
    var
    t,p,i,j:longint;
    y:boolean;
    a:array [0..10,0..10] of longint;
    b:array [0..10] of longint;

    procedure pd(dx,dy:longint);
    var i,j:longint;
    begin
    fillchar(b,sizeof(b),0);
    for i:=dx to dx+2 do
    for j:=dy to dy+2 do
    b[a[i,j]]:=1;
    for i:=1 to 9 do if b[i]=0 then y:=false;
    end;

    begin
    readln(t);
    for p:=1 to t do
    begin
    y:=true;
    for i:=1 to 9 do
    begin
    for j:=1 to 9 do read(a[i,j]);
    readln;
    end;
    for i:=1 to 9 do
    begin
    fillchar(b,sizeof(b),0);
    for j:=1 to 9 do b[a[i,j]]:=1;
    for j:=1 to 9 do
    if b[j]=0 then y:=false;
    end;
    for i:=1 to 9 do
    begin
    fillchar(b,sizeof(b),0);
    for j:=1 to 9 do b[a[j,i]]:=1;
    for j:=1 to 9 do
    if b[j]=0 then y:=false;
    end;
    pd(1,1);pd(1,4);pd(1,7);
    pd(4,1);pd(4,4);pd(4,7);
    pd(7,1);pd(7,4);pd(7,7);
    if y then writeln('Right') else writeln('Wrong');
    end;
    end.
    ```

  • 0
    @ 2016-08-26 11:29:03

    记录信息
    评测状态 Accepted
    题目 P1335 数独验证
    递交时间 2016-08-26 11:25:57
    代码语言 C++
    评测机 ShadowShore
    消耗时间 0 ms
    消耗内存 580 KiB
    评测时间 2016-08-26 11:25:59
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 576 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 576 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 580 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 576 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 576 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 580 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 576 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 576 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 572 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 576 KiB, score = 10
    Accepted, time = 0 ms, mem = 580 KiB, score = 100
    代码
    ```c++
    // input code here
    #include<bits/stdc++.h>
    using namespace std;
    bool Result[21];
    void Compute(int n)
    {
    bool f[10];
    int a[10][10],t[4][4];
    for(int i=1;i<=9;i++)
    for(int j=1;j<=9;j++)
    cin>>a[i][j];

    for(int i=1;i<=9;i++)
    {
    for(int i=1;i<=9;i++)
    f[i]=false;
    for(int j=1;j<=9;j++)
    f[a[i][j]]=true;
    for(int j=1;j<=9;j++)
    if(f[j]==false)
    {
    Result[n]=false;
    return;
    }
    }

    for(int i=1;i<=9;i++)
    {
    for(int i=1;i<=9;i++)
    f[i]=false;
    for(int j=1;j<=9;j++)
    f[a[j][i]]=true;
    for(int j=1;j<=9;j++)
    if(f[j]==false)
    {
    Result[n]=false;
    return;
    }
    }

    for(int i=0;i<=2;i++)
    {
    for(int j=0;j<=2;j++)
    {
    for(int k=1;k<=9;k++)
    f[k]=false;
    t[1][1]=a[1+(i*3)][1+(j*3)];
    t[1][2]=a[1+(i*3)][2+(j*3)];
    t[1][3]=a[1+(i*3)][3+(j*3)];
    t[2][1]=a[2+(i*3)][1+(j*3)];
    t[2][2]=a[2+(i*3)][2+(j*3)];
    t[2][3]=a[2+(i*3)][3+(j*3)];
    t[3][1]=a[3+(i*3)][1+(j*3)];
    t[3][2]=a[3+(i*3)][2+(j*3)];
    t[3][3]=a[3+(i*3)][3+(j*3)];
    for(int x=1;x<=3;x++)
    for(int y=1;y<=3;y++)
    f[t[x][y]]=true;
    for(int j=1;j<=9;j++)
    if(f[j]==false)
    {
    Result[n]=false;
    return;
    }
    }
    }

    Result[n]=true;
    return;
    }
    int main()
    {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    Compute(i);
    for(int i=1;i<=n;i++)
    if(Result[i]==true) cout<<"Right"<<endl;
    else cout<<"Wrong"<<endl;
    }
    ```

  • 0
    @ 2016-07-17 16:52:19

    测试数据 #0: Accepted, time = 0 ms, mem = 568 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 568 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 564 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 568 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 564 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 568 KiB, score = 10
    测试数据 #6: Accepted, time = 15 ms, mem = 564 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 568 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 572 KiB, score = 10
    测试数据 #9: Accepted, time = 15 ms, mem = 568 KiB, score = 10
    Accepted, time = 45 ms, mem = 572 KiB, score = 100
    c++
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    int s[21][9][9],ans[21];
    bool sameh(int d,int x,int y)//判断同行和同列有没有冲突
    {
    int i,j,k=0;
    for (i=1;i<=9;i++)
    if (i!=x && s[d][i][y]==s[d][x][y])
    k=1;
    else
    if (i!=y && s[d][x][i]==s[d][x][y])
    k=1;
    return k;
    }
    bool sameg(int d,int x,int y,int a,int b)//判断同一个3×3有没有冲突
    {
    int k=0;
    for (int i=1;i<=3;i++)
    for (int j=1;j<=3;j++)
    if (i+a!=x && j+b!=y && s[d][i+a][j+b]==s[d][x][y])
    k=1;
    return k;
    }
    int main()
    {
    int n,i,j,k;
    cin>>n;
    for (k=0;k<n;k++)
    for (i=1;i<=9;i++)
    for (j=1;j<=9;j++)
    cin>>s[k][i][j];
    for (k=0;k<n;k++)
    {
    int p=0;
    for (i=1;i<=9;i++)
    for (j=1;j<=9;j++)//每个点都列一遍咯
    {
    int a=0,b=0;
    if (i>3) a=3; if (i>6) a=6;
    if (j>3) b=3; if (j>6) b=6;
    if (sameh(k,i,j)) p=1;
    if (sameg(k,i,j,a,b)) p=1;
    }
    if (p) ans[k]=0;
    else ans[k]=1;
    }
    for (i=0;i<n;i++)
    {
    if (ans[i]==1) cout<<"Right"<<endl;
    else cout<<"Wrong"<<endl;
    }
    }

    暴力的过了

  • 0
    @ 2016-07-15 15:36:17
    注意**清数组**
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    int a[10];
    int b[10][10], c[10][10];
    int main() {
        int n;
        cin >> n;
        for(int o = 1; o <= n; o++) {
            int flag = true, x;
            memset(b, 0, sizeof b);
            for(int i = 1; i <= 9; i++) {
                memset(a, 0, sizeof a);
                for(int j = 1; j <= 9; j++) {
                    cin >> c[i][j];
                    x = c[i][j];
                    if(a[x] == 1 || b[j][x] == 1) 
                        flag = false;
                    else
                        a[x] = 1, b[j][x] = 1;
                }
            }
            int aa[10];
            for(int i = 1; i <= 3; i++)
                for(int j = 1; j <= 3; j++) {
                    memset(aa, 0, sizeof aa);
                    for(int k = 1; k <= 3; k++)
                        for(int l = 1; l <= 3; l++)
                            if(aa[c[i * 3 - 3 + k][j * 3 - 3 + l]] == 1)
                                flag = false;
                            else
                                aa[c[i * 3 - 3 + k][j * 3 - 3 + l]] = 1;
                }
            if(flag == true)
                cout << "Right" << endl;
            else
                cout << "Wrong" << endl;
        }
        system("pause");
        return 0;
    }
    
  • 0
    @ 2016-07-13 21:54:31

    #include <cstdio>
    #include <cstring>

    int main(){
    // freopen("in.txt","r",stdin);
    int n,ct[10],a[9][9];
    scanf("%d",&n);
    for(int k=1;k<=n;k++){
    for(int i=0;i<9;i++)
    for(int j=0;j<9;j++)
    scanf("%1d",&a[i][j]);
    int flag=1;
    for(int i=0;i<9;i++){
    memset(ct,0,sizeof(ct));
    for(int j=0;j<9;j++){
    if(ct[a[i][j]]==0)
    ct[a[i][j]]=1;
    else{
    flag=0;
    goto end;
    }
    }
    }

    for(int j=0;j<9;j++){
    memset(ct,0,sizeof(ct));
    for(int i=0;i<9;i++){
    if(ct[a[i][j]]==0)
    ct[a[i][j]]=1;
    else{
    flag=0;
    goto end;
    }
    }
    }
    for(int i=0;i<3;i++)
    for(int j=0;j<3;j++){
    memset(ct,0,sizeof(ct));
    for(int m=3*i;m<3*(i+1);m++)
    for(int n=3*j;n<3*(j+1);n++)
    if(ct[a[m][n]]==0)
    ct[a[m][n]]=1;
    else{
    flag=0;
    goto end;
    }
    }
    end:if(flag)
    printf("Right\n");
    else
    printf("Wrong\n");
    }
    return 0;
    }

  • 0
    @ 2016-07-12 16:50:18

    var i,j,k,n,x:integer;
    a,b:array[0..10,1..2] of longint;
    c:array[0..4,0..4,1..2] of longint;
    function nice:string;
    begin
    for j:=1 to 9 do
    if (a[j,1]<>45)or(a[j,2]<>362880)or(b[j,1]<>45)or(b[j,2]<>362880) then exit('Wrong');
    for j:=1 to 3 do
    for k:=1 to 3 do
    if (c[j,k,1]<>45)or(c[j,k,2]<>362880) then exit('Wrong');
    exit('Right');
    end;
    begin
    readln(n);
    for i:=1 to n do
    begin
    for j:=1 to 9 do
    begin
    a[j,1]:=0;
    a[j,2]:=1;
    b[j,1]:=0;
    b[j,2]:=1;
    end;
    for j:=1 to 3 do
    for k:=1 to 3 do
    begin
    c[j,k,1]:=0;
    c[j,k,2]:=1;
    end;
    for j:=1 to 9 do
    for k:=1 to 9 do
    begin
    read(x);
    inc(a[j,1],x);
    a[j,2]:=a[j,2]*x;
    inc(b[k,1],x);
    b[k,2]:=b[k,2]*x;
    inc(c[(j-1)div 3+1,(k-1)div 3+1,1],x);
    c[(j-1)div 3+1,(k-1)div 3+1,2]:=c[(j-1)div 3+1,(k-1)div 3+1,2]*x;
    end;
    writeln(nice);
    readln;
    end;
    end.
    呵呵!

  • 0
    @ 2016-06-18 12:08:09

    测试数据 #0: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 804 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 804 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #8: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 800 KiB, score = 10
    Accepted, time = 15 ms, mem = 804 KiB, score = 100
    -------------------------------华丽的分割线-------------------------------
    ```pascal
    type int=longint;
    var
    n,i,j,k,s1,s2,s3:int;
    f:boolean;
    a:array[0..9,0..9]of int;
    ff:array[1..9]of boolean;
    function hunter(x,y:int):boolean;
    var
    j,k:int;
    begin
    s1:=0; fillchar(ff,sizeof(ff),true);
    for j:=x to x+2 do
    for k:=y to y+2 do
    begin
    s1:=s1+a[j,k];
    if ff[a[j,k]] then ff[a[j,k]]:=false else exit(false);
    end;
    if s1<>45 then exit(false) else exit(true);
    end;

    begin
    readln(n);
    for i:=1 to n do
    begin
    f:=true;
    for j:=1 to 9 do
    for k:=1 to 9 do read(a[j,k]);
    for j:=1 to 9 do
    begin
    s1:=0; s2:=0;
    for k:=1 to 9 do
    begin
    s1:=a[j,k]+s1;
    s2:=a[k,j]+s2;
    end;
    if (s1<>45) or (s2<>45) then
    begin
    f:=false;
    break;
    end;
    end;
    if not f then writeln('Wrong') else
    begin
    for j:=1 to 3 do
    begin
    for k:=1 to 3 do if not hunter(3*j-2,3*k-2) then
    begin
    writeln('Wrong');
    f:=false;
    break;
    end;
    if not f then break;
    end;
    if f then writeln('Right');
    end;
    end;
    end.
    ```
    如果奇迹有颜色,那么一定是**紫色**!!!

  • 0
    @ 2016-06-09 07:55:19

    暴力枚举每一个数独,搞定!

信息

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