Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Infinitr Grid game,solution not giving correct resutl,please help

$
0
0

here is the link to question http://www.codechef.com/problems/IGAME

here is my code

#include<iostream>
#include<string>

using namespace std;

int main()
{
    short T=0,m=0,n=0; 
    short p=0,q=0,x=0,y=0;   
bool flag=true;
 short alice=1;
 short chk=0;

    cin>>T;

    chk=T;

    for(short i=0;i<T;i++)
    {

        short a=0;
        short r1,r2;
         alice=1;
        cin>>m>>n>>p>>q;
        x=m;y=n;
        a=min(m-p,n-q);
        flag=true;
        while(flag)
        {
         r1=x-p;
         r2=y-q;


     if((a>=r1 && a>=r2) && (a<=x && a<=y) &&  (x!=p && y!=q) )
     {

              x=x-a;
              y=y-a;

     }

    else if(x!=p)
     {
        if(x!=p)
             x=x-r1;
    }
    else if(y!=q)
      {
            y=y-r2;
      }

    if(x==p && y==q)
    {   flag=false;

        if(alice%2!=0)
        {   cout<<"Alice\n";

        }

        else if(alice%2==0)
        {
            cout<<"Bob\n";

        }
    }
    ++alice;
  }
  }



    return 0;
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>