Wednesday 31 July 2019

Monkey Banana Problem lightoj 1004

 In this problem we will check which adjacent cell will benefits the monkey best. For this, we will check all possible solution of this problem. For this course we will save previously solved subproblems and use it further.

codes:

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
    IOS
    int t;
    cin>>t;
    for(int no=1;no<=t;no++)
    {
        int n;
        cin>>n;
        ll arr[(2*n)-1][n];
        memset(arr,0,sizeof (arr[0][0])*((2*n)-1)*n);
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<=i;j++)
            {
                cin>>arr[i][j];
            }
        }
        for(int i=n;i<(2*n)-1;i++)
        {
            for(int j=0;j<((2*n)-1)-i;j++)
                cin>>arr[i][j];
        }
        for(int i=0;i<n;i++)
        {
            if(i==0) continue;
            for(int j=0;j<=i;j++)
            {
                ll x = 0, y = 0;
                if(j<i) x = arr[i-1][j];
                if(j>0) y = arr[i-1][j-1];
                arr[i][j] += max(x,y);
            }
        }
        for(int i=n;i<(2*n)-1;i++)
        {
            for(int j=0;j<((2*n)-1)-i;j++)
            {
                ll x = 0,y=0;
                x = arr[i-1][j];
                y = arr[i-1][j+1];
                arr[i][j] += max(x,y);
            }
        }
        cout <<"Case "<<no<<": " <<arr[(2*n)-2][0] <<endl;
    }
    return 0;
}

Tuesday 16 April 2019

Juice in the Glass LightOj 1216

In this problem we need to just find a equation,
a equation called conic  frustrum volume:
         
           V  = (pi*h /3) *(R*R + R*r + r*r)

code(c++):

/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define pi acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
    IOS
    int test,to=0;
    cin>>test;
    while(test--)
    {
        int r1,r2,h,p;
        cin>>r1>>r2>>h>>p;
        double pr= r2 +(r1-r2)*((double)p/h);
        double v;
        v = (pi*p)*(((double)pr*(double)pr)+((double)pr*(double)r2)+((double)r2*(double)r2))/3.0;
        printf("Case %d: %lf\n",++to,v);
    }
    return 0;
}



Intersection of Cubes LightOj 1211

To calculate intersection volume of n cubes, we need to find maximum value of first corner coordinates (x1,y1,z1) and minimum value of another corner coordinates(x2,y2,z2). There will be intersection between these cubes if and only if the difference between (x2-x1),(y2-y1),(z2-z1) is positive.

Code(c++):
/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
    IOS
    int test,tc=0;
    cin>>test;
    while(test--)
    {
        int n,a=0,b=0,c=0,d=INT_MAX,e=INT_MAX,f=INT_MAX;
        cin>>n;
        for(int i = 0;i<n;i++)
        {
            int x1,y1,z1,x2,y2,z2;
            cin>>x1>>y1>>z1>>x2>>y2>>z2;
            a = max(a,x1);
            b = max(b,y1);
            c = max(c,z1);
            d = min(d,x2);
            e = min(e,y2);
            f = min(f,z2);
        }
        if(d>a && e>b && f>c)
        {
            ll res = (d-a)*(e-b)*(f-c);
            cout << "Case "<< ++tc<< ": "<<res <<endl;
        }
        else
            cout << "Case "<< ++tc <<": 0\n";
    }
    return 0;
}

Sunday 14 April 2019

Bishops LightOj 1202

In this problem you just have to find out some conditions relevant to row and column differences.
One important thing is maximum move will be two(where one bishop can reach another but they are not in same diagonal)

so, you have to just find out conditions for each output(1,2 and impossible)


code:
/*
Author : Mohammad Morsalin Hossain
Dept of ICE,NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define IOS ios::sync_with_stdio(false);
using namespace std;
int main()
{
    IOS
    int test;
    cin>>test;
    int to=0;
    while(test--)
    {
        int row1,col1,row2,col2;
        cin>>row1>>col1>>row2>>col2;
        if((row1+col2 == row2+col1)||(abs(row1-row2)==abs(col1-col2)))
            cout << "Case "<<++to<<": 1\n";
        else if((row1+col2)==abs(row2-col1)||(abs(row1-col2)==row2+col1)||(row1+row2)%2==(col1+col2)%2)
            cout << "Case "<<++to<<": 2\n";
        else
            cout <<"Case "<<++to<<": impossible\n";
    }
    return 0;
}

Monkey Banana Problem lightoj 1004

  In this problem we will check which adjacent cell will benefits the monkey best. For this, we will check all possible solution of this pro...