Friday, May 1, 2015

448A - Rewards (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<n; i++)
#define MAX 100

int main()
{
    int n;
    float a1, a2, a3, slv_a;
    float b1, b2, b3, slv_b;
    cin >> a1 >> a2 >> a3;
    cin >> b1 >> b2 >> b3;
    cin >> n;

    slv_a = ceil((a1+a2+a3)/5);
    slv_b = ceil((b1+b2+b3)/10);

    if((slv_a+slv_b)<=n)
        cout <<"YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

450A - Jzzhu and Children (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<n; i++)
#define MAX 105
int a[MAX], index[MAX], step[MAX], step2[MAX], small[MAX];
float big[MAX];
int main()
{
    int n, m, ans, temp;
    int i, j, s=1, b=1, s2=1, sm=1;
    ans =0;
    temp =0;
    cin >> n >> m;
    i = 1;
    for(j=1; j<=n; j++)
    {
        cin >> a[j];
        small[sm++] = a[j];
        if(a[j]>m)
        {
            big[b] = a[j];
            index[i++] = j;
            step[s] = ceil(big[b]/m);
            step2[s2++] = step[s];
            b++;
            s++;
        }
    }
    if(b>1)
    {
        sort(step2, step2+s2);
        for(j=1; j<s; j++)
        {
            if(step2[s2-1]==step[j])
            {
                temp = j;
            }
        }
        ans = index[temp];
        cout << ans << endl;
    }
    else
    {
        i =1;
        for(j=1; j<=n ;j++)
        {
            if(small[sm-1]==a[j])
            {
                index[i++] = j;
            }
        }
        cout << index[i-1] << endl;
    }
    return 0;
}

451A - Game With Sticks (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<n; i++)
#define MAX 100

int min(int n, int m)
{
    if(n>m)
        return m;
    else
        return n;
}
int main()
{
    int n, m;
    cin >> n >> m;
    int temp = min(n, m);
    if(temp & 1)
       cout << "Akshat" << endl;
    else
       cout << "Malvika" << endl;
    return 0;
}

454A. Little Pony and Crystal Mine(Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define pf printf
#define sf scanf
#define MAX 105
char a[MAX][MAX];
int main()
{
    int i , j, n, temp=0, mid=0;
    memset(a, '*', sizeof(a));
    sf("%d", &n);
    mid = (n-1)/2;
    for(i=0; i<=n; i++)
    {
        for(j=mid; j<=mid+i; j++)
        {
            a[i][j] = 'D';
        }
        for(j=mid; j>=mid-i; j--)
        {
            a[i][j] = 'D';
        }
    }
    for(i=0; i<=mid; i++)
    {
        for(j=0; j<n; j++)
        {
            cout << a[i][j];
        }
        cout << endl;
    }
    for(i=mid-1; i>=0; i--)
    {
        for(j=0; j<n; j++)
        {
            cout << a[i][j];
        }
        cout << endl;
    }
    return 0;
}

UVa 11936. The Lazy Lumberjacks

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define sf scanf
#define pf printf
#define PI 2*acos(0.0)

int main()
{
   int t;
   sf("%d",&t);
   while(t--)
   {
       ll a, b, c;
       sf("%lld%lld%lld", &a, &b, &c);

       if(a+b>c && b+c>a && a+c>b)
            pf("OK\n");
       else
            pf("Wrong!!\n");
   }
   return 0;
}

Thursday, April 30, 2015

485A - Factory(Codeforces)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std ;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<n; i++)
#define MAX 500

int main()
{
    int a, m, i, rem;
    while(sf("%d%d", &a, &m)==2)
    {
        loop(i, MAX)
        {
            rem = (a%m);
             if(rem==0)
                break;
            a+=rem;
        }
         if(rem==0)
            pf("Yes\n");
         else
            pf("No\n");
    }
    return 0;
}

Tuesday, April 14, 2015

474A. Keyboard (Codeforces)

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define pf printf
#define sf scanf
using namespace std;

int main()
{
    string s = "qwertyuiopasdfghjkl;zxcvbnm,./'";
    string s1;
    int i, j, len;
    char input;
    sf("%c",&input);
    cin >> s1;
    len = s1.length();

    if(input == 'R')
    {
        for(i=0; i<len; i++)
        {
            for(j=0; j<31; j++)
            {
                if(s1[i]== s[j])
                {
                    pf("%c", s[j-1]);
                }
            }
        }
        pf("\n");
    }
    else if(input == 'L')
    {
        for(i=0; i<len; i++)
        {
            for(j=0; j<31; j++)
            {
                if(s1[i]== s[j])
                {
                    pf("%c", s[j+1]);
                }
            }
        }
        pf("\n");
    }
    return 0;
}

Compare equality of two string in C

#include <stdio.h> #include<string.h> int main() {     char* country = "Bangladesh";     char* country2;     ...