Thursday, December 15, 2016

1043 - Triangle Partitioning

Problem Linkhttp://lightoj.com/volume_showproblem.php?problem=1043

Solution :

#include<bits/stdc++.h>

using namespace std;

int main()
{

    double ab,ac,bc,r;
    int t;
    double ans;
    scanf("%d",&t);

    for(int ca=1; ca<=t; ca++)
    {
        cin>>ab>>ac>>bc>>r;

        r=(1/r)+1;

        ab=ab*ab;

        ans=sqrt(ab/r);
        printf("Case %d: %f\n",ca,ans);
    }


}

1253 - Misere Nim

Problem Linkhttp://lightoj.com/volume_showproblem.php?problem=1253

Solution :

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a[103];

    int t,k,ans,ok;

    scanf("%d",&t);

    for(int ca=1;ca<=t;ca++)
    {
        scanf("%d",&k);

        for(int i=1;i<=k;i++)
        {
            scanf("%d",&a[i]);
        }
            ok=0;

           for(int i=1;i<=k;i++)
           {
               if(a[i]==1) ok=1;
               else
               {
                   ok=0;
                   break;
               }
           }
           ans=0;
           for(int i=1;i<=k;i++)
           {
               ans=ans xor a[i];
           }

                if(ok==1 and (k%2!=0)) printf("Case %d: Bob\n",ca);
                else if(ok==1 and (k%2==0)) printf("Case %d: Alice\n",ca);
                else if(ans==0) printf("Case %d: Bob\n",ca);
                else printf("Case %d: Alice\n",ca);
        }

    }


Wednesday, December 14, 2016

1247 - Matrix Game

Problem Link : http://lightoj.com/volume_showproblem.php?problem=1247

Solution :

#include<bits/stdc++.h>

using namespace std;

vector<int>v;

int main()
{
    int t,m,n,sum,ans,a;

    scanf("%d",&t);

    for(int ca=1; ca<=t; ca++)
    {
        scanf("%d%d",&m,&n);

        for(int i=1; i<=m; i++)
        {
            sum=0;
            for(int j=1; j<=n; j++)
            {
                scanf("%d",&a);
                sum=sum+a;
            }
            v.push_back(sum);
        }

        ans=0;

        for(int i=0; i<v.size(); i++)
        {
            ans=ans xor v[i];
        }

        if(ans==0) printf("Case %d: Bob\n",ca);
        else printf("Case %d: Alice\n",ca);

        v.clear();
    }
}

1186 - Incredible Chess

Problem Link : http://lightoj.com/volume_showproblem.php?problem=1186

Solution :

#include<bits/stdc++.h>

using namespace std;

vector<int>v;

int main()
{
    int t,n,ans;

    int a[103],b[103];

    scanf("%d",&t);

    for(int ca=1;ca<=t;ca++)
    {
        scanf("%d",&n);

        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=1;i<=n;i++) scanf("%d",&b[i]);

        for(int i=1;i<=n;i++) v.push_back(b[i]-a[i]-1);

        ans=0;

        for(int i=0;i<v.size();i++) ans=ans xor v[i];

        if(ans==0) printf("Case %d: black wins\n",ca);
        else printf("Case %d: white wins\n",ca);

        v.clear();

    }

}

1192 - Left Right

Problem Link : http://lightoj.com/volume_showproblem.php?problem=1192

Solution :

#include<bits/stdc++.h>

using namespace std;

vector<int>v;

int main()
{
    int t,k,a,b,ans;
    scanf("%d",&t);

    for(int ca=1;ca<=t;ca++)
    {
        scanf("%d",&k);

        for(int i=1;i<=k;i++)
        {
            scanf("%d%d",&a,&b);
            v.push_back(b-a-1);
        }
        ans=0;
        for(int i=0;i<v.size();i++)
        {
            ans=ans xor v[i];
        }

        if(ans==0) printf("Case %d: Bob\n",ca);
        else printf("Case %d: Alice\n",ca);
        v.clear();
    }
}


Monday, November 14, 2016

1241 - Pinocchio

Problem Link : http://lightoj.com/volume_showproblem.php?problem=1241

Solution :

#include<bits/stdc++.h>
using namespace std;


int main()
{

    int t;
    scanf("%d",&t);

    int n,a,cnt,b,c;

    for(int ca=1; ca<=t; ca++)
    {
        cnt=0;
        a=-1;
        b=2;
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a);
            c=a-b;

            cnt=cnt+(c/5);
            if((c%5)!=0) cnt++;

            b=a;

        }
        printf("Case %d: %d\n",ca,cnt);
    }


}

1225 - Palindromic Numbers (II)

Problem Link : http://lightoj.com/volume_showproblem.php?problem=1225

Solution :

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t,l,m,cnt;
    char s[20];

    scanf("%d",&t);

    for(int ca=1;ca<=t;ca++)
    {
       scanf("%s",s);
       l=strlen(s);

       if(l%2==0) m=l/2;
       else m=(l/2)+1;
       cnt =1;

       for(int i=0;i<m;i++)
       {
          if(s[i]==s[l-i-1]);
          else
          {
              cnt=0;
              break;
          }
       }

       if(cnt==0) printf("Case %d: No\n",ca);
       else printf("Case %d: Yes\n",ca);

    }
}