Showing posts with label CF Solutions. Show all posts
Showing posts with label CF Solutions. Show all posts

Thursday, November 2, 2017

17A. Noldbach problem

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define ssf sscanf
#define spf sprintf
#define fsf fscanf
#define fpf fprintf
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pii pair <int,int>
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define U unsigned int
#define endl "\n"

const int MOD = 1000000007;
const int MAX = 1005;
bool prime[MAX];
vector <int> v;

int main (void)
{
    /*
    freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);
    */
    int i,j,n,k,c,val;

    prime[0] = prime[1] = 0;
    v.pb(2);

    for (i=4; i<MAX; i+=2)
        prime[i] = true;

    for (i=3; i*i<=MAX; i+=2)
        if (!prime[i])
            for (j=i*i; j<=MAX; j+=2*i)
                prime[j] = true;

    for (i=3; i<MAX; i+=2)
        if (!prime[i])
            v.pb(i);

    while (sf ("%d %d",&n,&k) != EOF)
    {
        c = 0;

        for (i=0; v[i]<=n; i++)
        {
            val = v[i]-1;

            for (j=0; v[j]<(val/2); j++)
            {
                if (v[j]+v[j+1] == val)
                {
                    ++c;
                    break;
                }
            }
        }

        if (c >= k)
            pf ("YES\n");
        else
            pf ("NO\n");
    }

    return 0;
}

Tuesday, October 24, 2017

877A. Alex and broken contest

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pii pair <int,int>
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define U unsigned int
#define endl "\n"

const int MOD = 1000000007;
const int MAX = 1000005;

int main (void)
{
    /*
    freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);
    */
    char str[105];
    int len,i,k;

    while (sf("%s",str) != EOF)
    {
        k = 0;
        len = strlen(str);

        for (i=0; i<len; i++)
        {
            if (str[i] == '_')
                continue;

            if (str[i] == 'D' && str[i+1] == 'a' && str[i+2] == 'n' && str[i+3] == 'i' && str[i+4] == 'l')
            {
                i += 4;
                ++k;
            }
            else if (str[i] == 'O' && str[i+1] == 'l' && str[i+2] == 'y' && str[i+3] == 'a')
            {
                i += 3;
                ++k;
            }
            else if (str[i] == 'S' && str[i+1] == 'l' && str[i+2] == 'a' && str[i+3] == 'v' && str[i+4] == 'a')
            {
                i += 4;
                ++k;
            }
            else if (str[i] == 'A' && str[i+1] == 'n' && str[i+2] == 'n')
            {
                i += 2;
                ++k;
            }
            else if (str[i] == 'N' && str[i+1] == 'i' && str[i+2] == 'k' && str[i+3] == 'i' && str[i+4] == 't' && str[i+5] == 'a')
            {
                i += 5;
                ++k;
            }
        }

        if (k == 1)
            pf ("YES\n");
        else
            pf ("NO\n");
    }

    return 0;
}

Sunday, September 10, 2017

617A. Elephant

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define u unsigned int

int main (void)
{
    int n;

    while (cin >> n)
        cout << ceil (n/5.0) << endl;

    return 0;
}

459A. I Wanna Be the Guy

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define u unsigned int

int main (void)
{
    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/

    int n,x,y,val;

    while (cin >> n)
    {
        set <int> myset;

        cin >> x;

        while (x--)
        {
            cin >> val;
            myset.in(val);
        }

        cin >> y;

        while (y--)
        {
            cin >> val;
            myset.in(val);
        }

        if (n == myset.size())
            cout << "I become the guy.\n";
        else
            cout << "Oh, my keyboard!\n";
    }

    return 0;
}

405A. Gravity Flip

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define u unsigned int

int main (void)
{
    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/

    int arr[105],n,i;

    while (cin >> n)
    {
        for (i=0; i<n; i++)
            cin >> arr[i];

        sort (arr,arr+i);

        for (i=0; i<n; i++)
        {
            cout << arr[i];

            if (i == n-1)
                cout << endl;
            else
                cout << " ";
        }
    }

    return 0;
}

835A. Key races

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define u unsigned int

int main (void)
{
    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/

    int s,v1,v2,t1,t2,a,b;

    while (cin >> s >> v1 >> v2 >> t1 >> t2)
    {
        a = 2*t1 + s*v1;
        b = 2*t2 + s*v2;

        if (a < b)
            pf("First\n");
        else if (a > b)
            pf ("Second\n");
        else
            pf ("Friendship\n");
    }

    return 0;
}

837A. Text Volume

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define u unsigned int

int main (void)
{
    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/

    int n,i,maxi,k;
    string str;

    while (cin >> n)
    {
        getchar();
        getline (cin,str);

        maxi = k = 0;

        for (i=0; i<n; i++)
        {
            if (isupper(str[i]))
                k++;

            maxi = max (k,maxi);

            if (str[i] == ' ')
                k = 0;
        }

        cout << maxi << endl;
    }

    return 0;
}

844A. Diversity

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define U unsigned int

int main (void)
{
    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/
    string str;
    int k,len,i;

    while (cin >> str >> k)
    {
        len = str.size();

        if (len < k)
            cout << "impossible\n";
        else
        {
            set <char> myset;

            for (i=0; i<len; i++)
                myset.in(str[i]);

            len = myset.size();

            if (len >= k)
                cout << 0 << endl;
            else
                cout << k-myset.size() << endl;
        }
    }

    return 0;
}

96A. Football

/***

            Bismillahir Rahmanir Rahim
            Read the name of Allah, who created you!!!
            Author : Shah Newaj Rabbi Shishir
            Department of CSE, City University, Bangladesh.

***/

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

#define sf scanf
#define pf printf
#define scase sf ("%d",&tc)
#define sn sf ("%d",&n)
#define whilecase while (tc--)
#define eof while (cin >> n)
#define forloop for (pos=1; pos<=tc; pos++)
#define arrayloop (i=0; i<n; i++)
#define cinstr cin >> str
#define getstr getline (cin,str)
#define pcase pf ("Case %d: ",pos)
#define pb push_back
#define in insert
#define llu unsigned long long
#define lld long long
#define U unsigned int

int main (void)
{
    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/
    int len,i,j,k;
    string str;
    bool val;

    while (cin >> str)
    {
        len = str.size();
        val = false;

        for (i=0; i<len; i++)
        {
            k = 0;

            for (j=i+1; j<len; j++)
            {
                if (str[i] == str[j])
                    k++;
                else
                    break;
            }

            if (k >= 6)
            {
                val = true;
                break;
            }
        }

        if (val)
            cout << "YES\n";
        else
            cout << "NO\n";
    }

    return 0;
}