Saturday 24 December 2016

Codeforces Round #386 (Div. 2)/A. Compote

Problem:http://codeforces.com/contest/746/problem/A
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,tmp,s,bb,cc;
    while(cin>>a>>b>>c)
    {
        bb=b/2;
        cc=c/4;
        tmp=a;
        if(tmp>cc)
            tmp=cc;
        if(tmp>bb)
            tmp=bb;
            //cout<<"tmp="<<tmp<<" "<<a<<" "<<bb<<" "<<cc<<endl;
            s=tmp*1+tmp*2+tmp*4;
            cout<<s<<endl;
    }
    return 0;
}

Codeforces Round #387 (Div. 2)/B. Mammoth's Genome Decoding

Problem:http://codeforces.com/contest/747/problem/B
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i,a,t,c,g,cc;
    char ar[260];
    while(cin>>n)
    {
        a=0;
        t=0;
        c=0;
        g=0;
        for(i=0; i<n; i++)
            cin>>ar[i];
        if(n%4!=0)
        {
            cout<<"==="<<endl;
            continue;
        }
        for(i=0; i<n; i++)
        {
            if(ar[i]=='A')
                a++;
            else if(ar[i]=='T')
                t++;
            else if(ar[i]=='C')
                c++;
            else if(ar[i]=='G')
                g++;
                //cout<<a<<" "<<t<<" "<<c<<" "<<g<<endl;
        }
        if(a>(n/4)||t>(n/4)||c>(n/4)||g>(n/4))
        {
            cout<<"==="<<endl;
            continue;
        }
        cc=0;
        while(cc<n)
        {

                if(a<n/4&&ar[cc]=='?')
                {
                    ar[cc]='A';
                    a++;
                    cc++;
                }
                 if(c<n/4&&ar[cc]=='?')
                {
                    ar[cc]='C';
                    c++;
                    cc++;
                }
                if(g<n/4&&ar[cc]=='?')
                {
                    ar[cc]='G';
                    g++;
                    cc++;
                }
                if(t<n/4&&ar[cc]=='?')
                {
                    ar[cc]='T';
                    t++;
                    cc++;
                }
                if(ar[cc]!='?')
                cc++;

        }
        for(i=0; i<n; i++)
            cout<<ar[i];
            cout<<endl;
    }
    return 0;
}

Friday 23 December 2016

Codeforces Round #387 (Div. 2)/A. Display Size

Problem:Codeforces Round #387 (Div. 2)/A. Display Size
Code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b,aa,bb,i;
    while(cin>>n)
    {
        aa=n;
        bb=1;
       for(i=1;i<=n;i++)
       {
           if(n%i==0)
           {
               a=n/i;
               b=i;
               //cout<<a<<" g "<<b<<endl;
               if(a<b)
                break;
           }
           if(aa-bb>a-b)
           {
               //cout<<bb<<" "<<aa<<" "<<b<<" "<<a<<endl;
               bb=b;
               aa=a;
           }
       }
       cout<<bb<<" "<<aa<<endl;
    }
    return 0;
}

Thursday 22 December 2016

Codeforces Round #388 (Div. 2)/B. Parallelogram is Back

Problem: Codeforces Round #388 (Div. 2)/B. Parallelogram is Back
Hints:                                        
এই তিন উপায়ে তিনটি সামান্তরিক তৈরি করা যায়।
আমরা জানি
১)সামান্তরিকের দুটি বিপরীত বাহু সমান্তরাল
২)(x,y),(x1,y1) এবং (x2,y2),(x3,y3)  দ্বারা গঠিত সরলরেখা দুটি সমান্তরাল হবে যদি x-x1=x2-x3 বা, x =x1+x2-x3
এবং y-y1=y2-y3 বা, y =y1+y2-y3
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long x1,x2,x3,y1,y2,y3;
    while(cin>>x1>>y1>>x2>>y2>>x3>>y3)
    {
        cout<<3<<endl;
        cout<<x1+x2-x3<<" "<<y1+y2-y3<<endl;
        cout<<x1+x3-x2<<" "<<y1+y3-y2<<endl;
        cout<<x2+x3-x1<<" "<<y2+y3-y1<<endl;
    }
    return 0;
}


Wednesday 21 December 2016

Codeforces Round #388 (Div. 2) A. Bachgold Problem

Problem: Codeforces Round #388 (Div. 2) A. Bachgold Problem
Code:
Hints:যে কোন জোর সংখ্যা কে তার অর্ধেক সংখ্যক ২ দারা যোগ করলে সেই সংখ্যা টি পাওয়া জায়।
এবং যে কোন বিজর সংখ্যা কে একটি ৩ আবন অর্ধেক এর থেকে একটি কম সংখ্যক ২ এর যোগফল আকারে প্রকাশ করা জায়।
যেমন,
10=2+2+2+2+2
11=2+2+2+2+3
Code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i;
    while(cin>>n)
    {
        cout<<n/2<<endl;
        if(n%2==0)
        for(i=1; i<=n/2; i++)
        {
            cout<<2;
            if(i!=n/2)
            cout<<" ";
        }
        else
            {for(i=1; i<=(n-3)/2; i++)
        {
            cout<<2;
            //if(i!=n/2)
            cout<<" ";
        }
        cout<<3;
            }
        cout<<endl;

    }
    return 0;
}