ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1637. Triangle Game 2

WA 8, please give me test!!!
Posted by Hasanov Dadaxon 15 Nov 2012 01:09
#include<stdio.h>
#include<iostream>
void swap(int &a, int &b)
{
   int t=a;a=b;b=t;
}
void ay(int &x1,int &x2, int &x3)
{
    if(x1>=x2&&x1>=x3)
    {
       x2=x1+(x1-x2);
       x3=x1+(x1-x3);
       return;
    }
    if(x2>=x1&&x2>=x3)
    {
       x1=x2+(x2-x1);
       x3=x2+(x2-x3);
       return;
    }
    if(x3>=x1&&x3>=x2)
    {
       x1=x3+(x3-x1);
       x2=x3+(x3-x2);
       return;
    }
}
int f(int _X1,int _X2,int _X3,int _x1,int _x2,int _x3)
{
    int X1=_X1,X2=_X2,X3=_X3,x1=_x1,x2=_x2,x3=_x3;

    if(X1==x1&&X2==x2&&X3==x3)return 0;

    ay(X1,X2,X3);
    if(x1-X1==x2-X2&&x1-X1==x3-X3&&(x1-X1)%2==0)return 1;

    ay(X1,X2,X3);
    if(x1-X1==x2-X2&&x1-X1==x3-X3&&(x1-X1)%2==0)return 2;
    return -1;
}
void ff(int &ans, int &k1, int &k2)
{
    if(k1!=-1&&k2!=-1&&k1+k2<ans)ans=k1+k2;
}
int main()
{
    int x1,y1,x2,y2,x3,y3,X1,Y1,X2,Y2,X3,Y3,ans=30;
    scanf("%i %i %i %i %i %i",&x1,&y1,&x2,&y2,&x3,&y3);
    scanf("%i %i %i %i %i %i",&X1,&Y1,&X2,&Y2,&X3,&Y3);

    int k1,k2;
    k1=f(X1,X2,X3,x1,x2,x3);   k2=f(Y1,Y2,Y3,y1,y2,y3);    ff(ans,k1,k2);
    k1=f(X1,X3,X2,x1,x2,x3);   k2=f(Y1,Y3,Y2,y1,y2,y3);    ff(ans,k1,k2);
    k1=f(X2,X1,X3,x1,x2,x3);   k2=f(Y2,Y1,Y3,y1,y2,y3);    ff(ans,k1,k2);
    k1=f(X2,X3,X1,x1,x2,x3);   k2=f(Y2,Y3,Y1,y1,y2,y3);    ff(ans,k1,k2);
    k1=f(X3,X1,X2,x1,x2,x3);   k2=f(Y3,Y1,Y2,y1,y2,y3);    ff(ans,k1,k2);
    k1=f(X3,X2,X1,x1,x2,x3);   k2=f(Y3,Y2,Y1,y1,y2,y3);    ff(ans,k1,k2);

    if(ans==30)puts("IMPOSSIBLE");
    else printf("%i",ans);
    return 0;
}


Thank's