Tuesday, 15 December 2015

Conversions (UVALive 3911, HDU 1985, ZOJ 2988, SPOJ GNY07B, Regionals 2007 >> North America - Greater NY)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

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

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100000


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n, m, x, y, a, b, c;
    double val;
    string s;
    cin>>tc;
    while(tc--)
    {
        cin>>val>>s;
        if(s=="kg") cout<< kk++ <<" "<<setprecision(4)<<fixed<<val*2.2046<<" lb\n";
        else if(s=="lb")    cout<< kk++ <<" "<<setprecision(4)<<fixed<<val*0.4536<<" kg\n";
        else if(s=="l")     cout<< kk++ <<" "<<setprecision(4)<<fixed<<val*0.2642<<" g\n";
        else if(s=="g")     cout<< kk++ <<" "<<setprecision(4)<<fixed<<val*3.7854<<" l\n";
    }
return 0;
}

Tuesday, 17 November 2015

Different Digits (UVA - 12527, UVALive 6134, Regionals 2012 >> Latin America)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

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

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100000


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n, m, x, y, a, b, c;
    bool arr[10];
    string s;
    //cin>>tc;
    while(cin>>n>>m)
    {
        int cnt=0;
        for(int i=n;i<=m;i++)
        {
            CLR(arr);
            x=i;
            while(x)
            {
                if(arr[x%10])
                {
                    cnt--;
                    break;
                }
                else arr[x%10]=true;
                x/=10;
            }
            cnt++;
        }
        cout<< cnt <<"\n";
    }
return 0;
}

Sunday, 11 October 2015

Speed Limit (UVALive 3059, HDU 3030, POJ 2017, ZOJ 2176, Regionals 2004 >> North America - Mid-Central USA)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

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

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100000


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n, x, t;
    string s;
    char ch;
    while(cin>>n && n!=-1)
    {
        int ans=0, pt=0;
        for(int i=0;i<n;i++)
        {
            cin>>x>>t;
            ans+=x*(t-pt);
            pt=t;
        }
        cout<< ans <<" miles\n";
    }
return 0;
}

Doubles (UVALive 2787, HDU 1303, ZOJ 1760, POJ 1552, Regionals 2003 >> North America - Mid-Central USA)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

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

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100000


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n, arr[20], x;
    bool exist[202];
    string s;
    char ch;
    while(cin>>x && x!=-1)
    {
        int n=0;
        arr[n++]=x;
        CLR(exist);
        exist[x]=true;
        while(cin>>x && x)
        {
            arr[n++]=x;
            exist[x]=true;
        }
        int cnt=0;
        for(int i=0;i<n;i++)
            if(exist[arr[i]*2])
                cnt++;
        cout<< cnt <<"\n";
    }
return 0;
}

Class Statistics (UVALive 5682, HDU 4176, Regionals 2011 >> South Pacific)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / uva / uvalive), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

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

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 100000


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int tc, kk=1, n, m, x, y, a, b, c, arr[55];
    string s;
    cin>>tc;
    while(tc--)
    {
        cin>>n;
        for(int i=0;i<n;i++) cin>>arr[i];
        sort(arr, arr+n);
        int gap=0;
        for(int i=1;i<n;i++) gap=max(gap, arr[i]-arr[i-1]);
        cout<<"Class "<<kk++<<"\n";
        cout<< "Max "<<arr[n-1]<<", Min "<<arr[0]<<", Largest gap "<<gap<<"\n";
    }
return 0;
}