Saturday 22 August 2015

SPOJ-TRGRID




try to solve this as for a square grid...
take the min of the row and column (be x)and find the value for the grid(x,x)


now your answer wont change if the grid is originally a horizontal rectangle but may vary if the grid is vertical rectangle


.. think yourself and u will get what i meant...



1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<bits/stdc++.h>
int min(int x,int y)
{
    return (x<y)?x:y;
}
int max(int x,int y)
{
    return (x>y)?x:y;
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int m,n,x;
        scanf("%d %d",&n,&m);
        x=min(n,m);
        char ch;
        ch=(x&1)?'R':'L';
        if(n>m && m&1)ch='D';
        if(n>m && !(m&1))ch='U';
        printf("%c\n",ch);
    }
    return 0;
}

No comments:

Post a Comment