Showing posts with label LIGHT OJ. Show all posts
Showing posts with label LIGHT OJ. Show all posts

Saturday, 26 March 2016

Solution of LIGHT OJ 1225 :: Palindromic Numbers (II)


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int digit(int x)
{
    int d=0;
    while(x)
    {
        x/=10;
        d++;
    }
    return d;
}
int main()
{
    int a,b,c,d,e,f=0,g,h,i=0,j=0;
    scanf("%d", &a);
    for(b=1; b<=a; b++)
    {
        scanf("%d", &c);
        d=digit(c);
        int ara[d];
        while(c)
        {
            e=c%10;
            c/=10;
            ara[f]=e;
            f++;
        }
        f=0;
        g=d/2;
        i=d-1;
        for(h=0,j=0; h<g; h++)
        {
            if(ara[h]==ara[i])
                j++;
            i--;
        }
        i=0;
        if(j==g)
            printf("Case %d: Yes\n",b);
        else
            printf("Case %d: No\n",b);
    }
    return 0;
}

Solution of LIGHT OJ 1214 :: Large Division


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahimm**/

#include <stdio.h>
int main()
{
    long long int tst, i, j, b, dcml;
    char a[1000];
    scanf("%lld", &tst);
    for(i=1; i<=tst; i++)
    {
        long long int mod_a=0, div_a=0;
        scanf("%s", a);
        scanf("%lld", &b);
        j=0;
        if(a[0]=='-') j=1;
        while(a[j])
        {
            dcml = a[j] - 48;
            div_a+=dcml;
            mod_a = div_a%b;
            div_a= mod_a*10;
            j++;
        }
        if(mod_a==0) printf("Case %lld: divisible\n", i);
        else printf("Case %lld: not divisible\n", i);
    }
    return 0;
}

Solution of LIGHT OJ 1182 :: Parity


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d=0,T,n,e=0;
    while((scanf("%d", &T))==1)
    {
        e=0;
        for(b=1; b<=T; b++)
        {
            scanf("%d", &n);
            while(n)
            {
                c=n%2;
                d+=c;
                n/=2;
            }
            e++;
            if(d%2==0)
                printf("Case %d: even\n",e);
            else{
                printf("Case %d: odd\n",e);
                d=0;
            }
        }
    }
    return 0;
}

Solution of LIGHT OJ 1202 :: Bishops


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim**/

#include <stdio.h>
#include <math.h>
int main()
{
    int tst, i;
    scanf("%d", &tst);
    for(i=1; i<=tst; i++)
    {
        int r1,c1,r2,c2,r,c;
        scanf("%d%d%d%d", &r1, &c1, &r2, &c2);
        if((r1%2==1 && c1%2==0) || (r1%2==0 && c1%2==1))
        {
            if((r2%2==0 && c2%2==0) || (r2%2==1 && c2%2==1))
                printf("Case %d: impossible\n", i);
            else
            {
                r = abs(r1-r2);
                c = abs(c1-c2);
                if(r==c) printf("Case %d: 1\n", i);
                else printf("Case %d: 2\n", i);
            }
        }
        else if((r1%2==1 && c1%2==1) || (r1%2==0 && c1%2==0))
        {
            if((r2%2==1 && c2%2==0) || (r2%2==0 && c2%2==1))
                printf("Case %d: impossible\n", i);
            else
            {
                r = abs(r1-r2);
                c = abs(c1-c2);
                if(r==c) printf("Case %d: 1\n", i);
                else printf("Case %d: 2\n", i);
            }
        }
    }
    return 0;
}

Solution of LIGHT OJ 1136 :: Division by 3


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d,e,f,g,h,i,j,k,l,m,n;
    scanf("%d", &a);
    for(b=1; b<=a; b++)
    {
        scanf("%d%d", &c, &d);
        e=(c/3)*2;
        f=c%3;
        if(f==2)
            e+=1;
        i=(d/3)*2;
        j=d%3;
        if(j==2)
            i+=1;
        m=i-e;
        m+=1;
        if(f==1)
            m-=1;
        printf("Case %d: %d\n",b,m);
    }
    return 0;
}

Solution of LIGHT OJ 1133 :: Array Simulation


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int tst, i;
    scanf("%d", &tst);
    for(i=1; i<=tst; i++)
    {
        int n, m, D;
        scanf("%d%d", &n, &m);
        int ara[n], j, k, l, tmp, x, y;
        for(j=0; j<n; j++)
            scanf("%d", &ara[j]);
        for(k=0; k<m; k++)
        {
            char step[2];
            scanf("%s", step);
            if(step[0]=='S')
            {
                scanf("%d", &D);
                for(j=0; j<n; j++)
                    ara[j]+=D;
            }
            else if(step[0]=='M')
            {
                scanf("%d", &D);
                for(j=0; j<n; j++)
                    ara[j]*=D;
            }
            else if(step[0]=='D')
            {
                scanf("%d", &D);
                for(j=0; j<n; j++)
                    ara[j]/=D;
            }
            else if(step[0]=='R')
            {
                for(j=0,l=n-1; j<n/2; j++, l--)
                {
                    tmp = ara[j];
                    ara[j] = ara[l];
                    ara[l] = tmp;
                }
            }
            else if(step[0]=='P')
            {
                scanf("%d%d", &x, &y);
                tmp = ara[x];
                ara[x] = ara[y];
                ara[y] = tmp;
            }
        }
        printf("Case %d:\n", i);
        for(j=0; j<n-1; j++)
            printf("%d ", ara[j]);
        printf("%d\n", ara[j]);
    }
    return 0;
}

Solution of LIGHT OJ 1107 :: How Cow


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d,e,f,g,h,i,j,x1,x2,y1,y2;
    scanf("%d", &a);
    for(b=1; b<=a; b++)
    {
        printf("Case %d:\n",b);
        scanf("%d%d%d%d", &x1,&y1,&x2,&y2);
        scanf("%d", &c);
        for(d=1; d<=c; d++)
        {
            scanf("%d %d", &e, &f);
            if(((e>=x1) &&(e<=x2)) && ((f>=y1)&&(f<=y2)))
                printf("Yes\n");
            else
                printf("No\n");
        }
    }
    return 0;
}

Solution of LIGHT OJ 1116 :: Ekka Dokka


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <math.h>
int main()
{
    long long int m, n, w;
    long long int tst, i, j, odd, Valid, limit;
    scanf("%lld", &tst);
    for(i=1; i<=tst; i++)
    {
        scanf("%lld", &w);
        limit = w/2;
        Valid = 0;
        odd = 0;
        for(j=2; j <= limit;  j *= 2)
        {
            if(w%j == 0)
                odd = w/j;
            if(odd%2 == 1)
            {
                Valid = 1;
                break;
            }
        }
        if(Valid==1)
            printf("Case %lld: %lld %lld\n", i, odd, j);
        else
            printf("Case %lld: Impossible\n", i);
    }
    return 0;
}

Solution of LIGHT OJ 1109 :: False Ordering


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <math.h>

int ara[1001],k, cnt, j, tmp;

void square(int ara[])
{
    for(k=1; k<=32; k++)
        ara[k*k]=-1;
}

void devisor(int ara[])
{
    for(k=1; k<=1000; k++)
    {
        tmp = sqrt(k);
        for(j=1, cnt=0; j<=tmp; j++)
        {
            if(k%j==0)
                cnt++;
        }
        ara[k]+=(cnt*2);
    }
}

int main()
{
    int tst, i, fnl[1001], n;
    scanf("%d", &tst);
    int l=2; fnl[1] = 1;
    square(ara);
    devisor(ara);
    for(j=2; j<=32; j++)
    {
        for(k=1000; k>=2; k--)
        {
            if(ara[k]==j)
            {
                fnl[l]=k;
                l++;
            }
        }
    }
    for(i=1; i<=tst; i++)
    {
        scanf("%d", &n);
        printf("Case %d: %d\n", i, fnl[n]);
    }
    return 0;
}

Solution of LIGHT OJ 1072 :: Calm Down


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <math.h>
#define PI acos(0.0)*2
int main()
{
    int x,y,z;
    double a,b,c,d,f,g,h;
    double e;
    scanf("%d", &x);
    for(y=1; y<=x; y++){
        scanf("%lf%lf", &a, &b);
        c=(PI/b);
        d=sin(c);
        e=(a*d)/(1+d);
        z=(int) e;
        h=(e*1.0)/z;
        if(h!=1)
           printf("Case %d: %.10lf\n",y, e);
        else
           printf("Case %d: %.0lf\n",y, e);
    }
    return 0;
}

Solution of LIGHT OJ 1069 :: Lift


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d,e,f;
    scanf("%d", &c);
    for(d=1; d<=c; d++)
    {
        scanf("%d%d", &a, &b);
        if(a<=b)
            e=b*4+19;
        else
            e=(2*a-b)*4 +19;
        printf("Case %d: %d\n", d,e);
    }
    return 0;
}

Solution of LIGHT OJ 1053 :: Higher Math


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    long long int a,b,c,d,e,f,g,h;
    scanf("%lld", &d);
    for(e=1; e<=d; e++)
    {
        scanf("%lld%lld%lld", &a, &b, &c);
        if(a>b && a>c)
        {
            f=a*a;
            g=b*b+c*c;
        }
        else if(b>a && b>c)
        {
            f=b*b;
            g=a*a+c*c;
        }
        else if(c>a && c>b)
        {
            f=c*c;
            g=a*a+b*b;
        }
        if(f==g)
            printf("Case %d: yes\n",e);
        else
            printf("Case %d: no\n",e);
    }
    return 0;
}

Friday, 25 March 2016

Solution of LIGHT OJ 1022 :: Circle in Square


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <math.h>
#define PI 2*acos(0.0)
int main()
{
    int a,b;
    double c,d,e,f,g,h,r;
    scanf("%d", &b);
    for(a=1; a<=b; a++)
    {
        scanf("%lf", &r);
        c=((r+r)*(r+r))-(PI*r*r);
        printf("Case %d: %.2lf\n",a,c);
    }
    return 0;
}

Solution of LIGHT OJ 1015 :: Brush (I)


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d,e,f=0,g=0;
    scanf("%d",&a);
    for(b=1; b<=a; b++)
    {
        scanf("%d", &c);
        for(d=1,f=0; d<=c; d++)
        {
            scanf("%d",&e);
            if(e>0) f+=e;
        }
        if(f>=0)
            printf("Case %d: %d\n",b,f);
    }
    return 0;
}

Solution of LIGHT OJ 1010 :: Knights in Chessboard


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int tst, i;
    int m , n, mn, ans, x;
    scanf("%d", &tst);
    for(i=1; i<=tst; i++)
    {
        scanf("%d%d", &m, &n);
        mn = m * n;
        if(m==1 || n==1)    ans = mn;
        else if(m==2 || n==2)
        {
            if(m==2) x = n;
            else     x = m;
            if(x%4 == 1)      ans = x+1;
            else if(x%4 == 2) ans = x+2;
            else if(x%4 == 3) ans = x+1;
            else if(x%4 == 0) ans = x;
        }
        else if(mn%2 == 0) ans = mn/2;
        else ans = (mn/2)+1;
        printf("Case %d: %d\n", i, ans);
    }
    return 0;
}

Solution of LIGHT OJ 1006 :: Hex-a-bonacci


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
    {
    long long int a, b, c, d, e, f;
    long long int ara[10000], m;
    int n, caseno = 0, cases;
    scanf("%lld", &cases);
    while( cases-- )
    {
        scanf("%lld %lld %lld %lld %lld %lld %d", &ara[0], &ara[1], &ara[2], &ara[3], &ara[4], &ara[5], &n);
        for(m=6; m<=n; m++)
            ara[m]=(ara[m-1]+ara[m-2]+ara[m-3]+ara[m-4]+ara[m-5]+ara[m-6])%10000007;

        printf("Case %d: %lld\n", ++caseno, ara[n]  % 10000007);
    }
    return 0;
}

Solution of LIGHT OJ 1001 :: Opposite Task


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b,c,d,e;
    scanf("%d", &a);
    for(b=0; b<a; b++)
    {
        scanf ("%d", &c);
        if(c>10)
        {
            d=c-10;
            e=10;
            printf("%d %d\n",d,e);
        }
        else
        {
            d=0;
            printf("%d %d\n",d,c);
        }
    }
    return 0;
}

Wednesday, 20 January 2016

Solution of URI 1323 :: UVA 12149 :: LIVE ARCHIVE 4215 :: Feynman


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int a,b;
    while(1)
    {
        scanf("%d", &a);
        if(a==0) break;
        else b=(a*(a+1)*((2*a)+1))/6;
        printf("%d\n",b);
    }
    return 0;
}


Wednesday, 13 January 2016

Solution of LIGHT OJ 1389 :: Scarecrow


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int tst, k, cnt, ans, i;
    scanf("%d", &tst);
    for(k=1; k<=tst; k++)
    {
        int n;
        scanf("%d", &n);
        char field[n+1];
        scanf("%s", field);
        for(i=0, cnt=0, ans = 0; i<n; i++)
        {
            if(field[i] == '.')
            {
                ans++;
                i += 2;
            }
        }
        printf("Case %d: %d\n", k, ans);
    }
    return 0;
}

Monday, 11 January 2016

Solution of LIGHT OJ 1433 :: Minimum Arc Distance


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
#include <math.h>
#define PI 2*acos(0.0)
int main()
{
    int tst, i;
    scanf("%d", &tst);
    for(i=1; i<=tst; i++)
    {
    double ox, oy, ax, ay, bx, by;
    double oa, ob, ab, ans, angle, perameter,cos,c,d;
    scanf("%lf%lf%lf%lf%lf%lf", &ox, &oy, &ax, &ay, &bx, &by);
    c = ox-ax; d= oy-ay;
    oa = pow(c, 2) + pow(d,2);
    oa = sqrt(oa);
    ob = pow((ox-bx), 2) + pow((oy-by),2);
    ob = sqrt(ob);
    ab = pow((bx-ax), 2) + pow((by-ay),2);
    ab = sqrt(ab);
    perameter = 2*PI*oa;
    cos = (pow(oa,2) + pow(ob,2) + pow(ab,2))/(2*oa*ob);
    angle = acos(cos);
    ans = (perameter/360.00)/angle;
    printf("Case %d: %lf\n", i,angle);
    }
    return 0;
}