Cod sursă (job #295607)

Utilizator avatar micutu Andrei Vasile Cont Fraudulent micutu IP ascuns
Problemă Immortal (clasele 9-10) Compilator cpp | 2,71 kb
Rundă Arhiva de probleme Status evaluat
Dată 26 mar. 2017 06:51:53 Scor 30
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("immortal.in");
ofstream g("immortal.out");

int gasit = 0;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int n , m , I ;
int a[25][25] ;

struct nemuritor
{
    int x,y;
}v[16];

struct solutie
{
    int x1,x2,y1,y2;
}sol[16];

void afis ()
{
    for ( int i = 1; i <= I-1; i++ )
        g << sol[i].x1 << " " << sol[i].y1 << " " << sol[i].x2 << " " << sol[i].y2 << "\n" ;
}

bool interior ( int x , int y )
{
    return x <= n and x >= 1 and y <= m and y >=1 ;
}

void afisare()
{
    for ( int r = 1 ; r <= I-1 ; r++ )
    {
        g << sol[r].x1 << " " << sol[r].y1 << " " << sol[r+1].x2 << " " << sol[r+1].y2 << "\n" ;
    }
}

void back (int nr , int lg )
{
    if ( nr == 1 and !gasit)
    {
        gasit = 1;
        afis();
        return;
    }
    else
    {
        for ( int i = 1; i <= I and !gasit; i++ )
        {
            int ox = v[i].x;
            int oy = v[i].y;
            if ( a[ox][oy] == 1 )
            {
                if (ox >2 and a[ox-1][oy] == 1 and a[ox-2][oy] == 0 ) v[i].x-=2,  a[ox-1][oy] = 0 , swap(a[ox][oy],a[ox-2][oy]), sol[lg].x1 = ox , sol[lg].y1 = oy , sol[lg].x2 = ox-2 , sol[lg].y2 = oy , back(nr-1,lg+1) , a[ox-1][oy] = 1 , swap(a[ox][oy],a[ox-2][oy]) , v[i].x+=2;;
                if (ox+2 <=n and a[ox+1][oy] == 1 and a[ox+2][oy] == 0 )v[i].x+=2,  a[ox+1][oy] = 0 , swap(a[ox][oy],a[ox+2][oy]), sol[lg].x1 = ox , sol[lg].y1 = oy , sol[lg].x2 = ox+2 , sol[lg].y2 = oy , back(nr-1,lg+1) , a[ox+1][oy] = 1 , swap(a[ox][oy],a[ox+2][oy]),v[i].x-=2;;
                if (oy >2 and a[ox][oy-1] == 1 and a[ox][oy-2] == 0 ) v[i].y-=2, a[ox][oy-1] = 0 , swap(a[ox][oy],a[ox][oy-2]), sol[lg].x1 = ox , sol[lg].y1 = oy , sol[lg].x2 = ox , sol[lg].y2 = oy-2 , back(nr-1,lg+1) , a[ox][oy-1] = 1 , swap(a[ox][oy],a[ox][oy-2]),v[i].y+=2;
                if (oy+2 <=m and a[ox][oy+1] == 1 and a[ox][oy+2] == 0 ) v[i].y+=2, a[ox][oy+1] = 0 , swap(a[ox][oy],a[ox][oy+2]), sol[lg].x1 = ox , sol[lg].y1 = oy , sol[lg].x2 = ox , sol[lg].y2 = oy+2 , back(nr-1,lg+1) , a[ox][oy+1] = 1 , swap(a[ox][oy],a[ox][oy+2]),v[i].y-=2;
            }
        }
    }

}


int main()
{
    f >> n >> m >> I;
    for ( int i = 1 ; i <= I; i++ )
    {
        f >> v[i].x >> v[i].y ;
        a[ v[i].x ][ v[i].y ] = 1;
    }
    int nr = I;
    back(nr,1);
    long long e = 994010994000;
    int A[8];
   A[0] = 6;
   A[6] = 0;
   A[5] = 0;
   A[4] = 2;
   A[3] = 1;
   A[2] = 2;
   A[1] = 4;
   /*A[7] = 0;
   A[8] = 1;
   A[9] = 0;
   A[10] = 4;
   A[11] = 9;
   A[12] = 9;*/
  int R =0 ;
  int X = 9973;
  for (int i=A[0];i;i--)
    R=(10*R+A[i])%X;
    cout << R;

    return 0;
}