Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     ios_base::sync_with_stdio(false);
  7.    int n,m,t;
  8.    cin>>n>>m>>t;
  9.    int *a=new int [n*m];
  10.    int b[100000],k=0;
  11.    int pos[300][300]={0};
  12.    for(int i=0;i<n*m;i++){
  13.         cin>>a[i];
  14.         if(a[i]!=0){
  15.             b[k]=a[i];
  16.             k++;
  17.         }
  18.    }
  19.    stable_sort(b,b+k);
  20.    if(t+1<k){
  21.         cout<<"Wrong Board";
  22.         return 0;
  23.    }
  24.    int x1=-1,y1=-1;
  25.    for(int i=0;i<k;i++){
  26.         int pos1=(find(a,a+n*k,b[i])-a);
  27.         int y=(pos1/m),x=(pos1%m);
  28.         if(i>0){
  29.             if((abs(x1-x)!=abs(y1-y))&& (x1!=x) && (y1!=y)){
  30.                 cout<<"Wrong Board";
  31.                 return 0;
  32.             }
  33.             else{
  34.                 pos[y][x]=(i+1);
  35.             }
  36.         }
  37.          pos[y][x]=(i+1);
  38.         y1=y,x1=x;
  39.    }
  40.    for(int i=0;i<n;i++){
  41.         for(int j=0;j<m;j++){
  42.             cout<<pos[i][j]<<" ";
  43.         }
  44.         cout<<endl;
  45.    }
  46.    return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement