Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream f("panda.in");
  4. ofstream g("panda.out");
  5.  
  6. bool complementare(int a, int b, int s)
  7. {
  8.     bitset<8> aBin;
  9.     bitset<8> bBin;
  10.  
  11.     int i = 0;
  12.     int j = 0;
  13.  
  14.     int aux = 8;
  15.     while(aux!=0)
  16.     {
  17.         --aux;
  18.         aBin[i++] = a%2;
  19.         a/=2;
  20.     }
  21.     aux = 8;
  22.     while(aux!=0)
  23.     {
  24.         --aux;
  25.         bBin[j++] = b%2;
  26.         b/=2;
  27.     }
  28.  
  29.  
  30.     for(int z = 0; z<s; ++z)
  31.     {
  32.         if(aBin[z]==0 && bBin[z]==0) return false;
  33.         if(aBin[z]==1 && bBin[z]==1) return false;
  34.     }
  35.     return true;
  36. }
  37.  
  38. struct {
  39.     int lin;
  40.     int col;
  41. }C[10001],ps,pf;
  42.  
  43. int p,n,m,t,i,j,v[1001][1001],l,c,k,s,a[1001][1001],x,P,pm,um,K,dl[]={-1,0,1,0},dc[]={0,1,0,-1},vc;
  44. int main()
  45. {
  46.     f>>P;
  47.     f>>n>>m>>t;
  48.     f>>l>>c>>k>>s;
  49.     for(i=1;i<=t;++i)
  50.         for(j=1;j<=2;++j)
  51.             f>>a[i][j];
  52.     for(i=1;i<=n;++i)
  53.         for(j=1;j<=m;++j)
  54.             f>>v[i][j];
  55.     if(P==1){
  56.         for(i=1;i<=n;++i){
  57.             for(j=1;j<=m;++j){
  58.                 if(complementare(v[i][j],k,s)) x++;
  59.             }
  60.         }
  61.         g<<x-1;
  62.     }
  63.     else{
  64.         for(i=0;i<=n+1;++i)
  65.            v[i][0]=v[i][m+1]=-1;
  66.         for(j=0;j<=m+1;j++)
  67.            v[0][j]=v[n+1][j]=-1;
  68.         pm=um=0;
  69.         C[0]=ps;
  70.         v[ps.lin][ps.col]=1;
  71.         while(pm<=um && v[pf.lin][pf.col]==0){
  72.             p=C[pm];
  73.             pm++;
  74.             for(K=0;K<4;k++){
  75.                 vc.lin=p.lin+dl[k]; vc.col=p.col+dc[p];
  76.                 if(v[vc.lin][vc.col]==0){
  77.                     v[vc.lin][vc.col]=v[p.lin][p.col]+1;
  78.                     um++;C[um]=vc;
  79.                 }
  80.             }
  81.         }
  82.         cout<<v[pf.lin][pf.col];
  83.     }
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement