spoj 62

看了题解  自己好水   ......


#include <cstdio>
#include <cstdlib>

struct node
{
    int x,y;
};
node A,B;

node add(node &a,node &b)
{
    node f;
    f.x = a.x+b.x;
    f.y = a.y+b.y;
    return f;
}

node re(node &a,node &b)
{
    node f;
    f.x = a.x-b.x;
    f.y = a.y-b.y;
    return f;
}

int cc(node a)
{
    return abs(a.x)+abs(a.y);
}

int main()
{
    int a;
    int t = 10;
    while(t--)
    {
        scanf("%d%d%d%d",&A.x,&A.y,&B.x,&B.y);
        int flag = 1;
        while(flag)
        {
            flag = 0;
            while(cc(add(A, B)) < cc(A))
                A = add(A,B), flag = 1;
            while(cc(re(A, B)) < cc(A))
                A = re(A, B), flag = 1;
            while(cc(add(B, A)) < cc(B))
                B = add(B, A), flag = 1;
            while(cc(re(B, A)) < cc(B))
                B = re(B, A), flag = 1;
        }
        if(cc(A) == 0)
            a = cc(B);
        else if(cc(B) == 0)
            a = cc(A);
        else if(cc(A) < cc(B))
            a = cc(A);
        else
            a = cc(B);
        printf("%d\n",a);
    }
    return 0;
}


posted @ 2013-08-07 15:10  xlc2845  阅读(111)  评论(0)    收藏  举报