(LightOj) 1064 – Throwing Dice

0

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>

#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>


#define FOR(i, s, e) for(int i=s; i<e; i++)
#define loop(i, n) FOR(i, 0, n)
#define sf scanf
#define pf printf
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define ll long long
#define dd double
#define all(v) v.begin(), v.end()
#define PI acos(-1.0)
#define mem(ara, value) memset(ara, value, sizeof(ara))
#define paii pair<int, int>
#define pall pair<ll, ll>
#define SZ(a) int(a.size())
#define read(nm) freopen(nm, "r", stdin)
#define write(nm) freopen(nm, "w", stdout)
#define dump(x) cout<<#x<<" = "<<x<<endl

using namespace std;

#define take(args...) asdf,args
#define debug(args...) asdfg,args; cout<<endl
struct ASDF{
    ASDF& operator,(int &a) {
        sf("%d", &a);
        return *this;
    }
    ASDF& operator,(long int &a){
        sf("%ld", &a);
        return *this;
    }
    ASDF& operator,(long long int &a){
        sf("%lld", &a);
        return *this;
    }
    ASDF& operator,(char &c){
        sf("%c", &c);
        return *this;
    }
    ASDF& operator,(double &d){
        sf("%lf", &d);
        return *this;
    }

    template<typename T>
    ASDF& operator,(T &a){
        cin>>a;
        return *this;
    }
}asdf;
struct ASDFG{
    template<typename T>
    ASDFG& operator,(vector<T> &v){
        pf("[");
        cout<<v[0];
        FOR(i, 1, SZ(v)){
            cout<<", "<<v[i];
        }
        pf("]");
        return *this;
    }

    template<typename T>
    ASDFG& operator,(T x) {
        cout<<x<<" ";
        return *this;
    }


}asdfg;



//Header ends here
#define MAXX 152

ll cnt[MAXX];

int main()
{
    int kases, kaseno = 0;

    take(kases);
    int n, x;

    while(kases--)
    {
        take(n, x);
        mem(cnt, 0);

        cnt[0] = 1;
        int mx;
        loop(tt, n)
        {
            mx = 6*tt;

            for(int i=mx; i>-1; i--)
            {
                FOR(j, 1, 7)
                {
                    cnt[i+j] += cnt[i];
                }

                cnt[i] = 0;
            }
        }
        ll upre = 0, nice = 0;
        mx = 6*n;
        for(int i=x; i<=mx; i++) upre += cnt[i];
        for(int i=1; i<x; i++) nice += cnt[i];
        nice += upre;

        ll g = __gcd(upre, nice);
        upre /= g;
        nice /= g;

        pf("Case %d: ", ++kaseno);
        if(nice == 1) pf("%lld\n", upre);
        else pf("%lld/%lld\n", upre, nice);



    }


}


# Important notes for USING MAP

0

The disadvantages of using map’s [] operator:

#If the key doesn’t exists then a new key with default value will be allocated.
# This operators complexity is Logarithmic in size.
# Map’s size will be increased.

So, what can we use??? There is a good member function called “count()”. The definition of of count() is:
Searches the container for an element with a key of x and returns the number of elements having that key. Because map containers do not allow for duplicate keys, this means that the function actually returns 1 if an element with that key is found, and zero otherwise.

# This count() method doesn’t create a new key if the key doesn’t exist.
# This operators complexity is logarithmic in size.
# Map’s size won’t be increased.

My C++ Code Template

0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>

#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>


#define FOR(i, s, e) for(int i=s; i<e; i++)
#define loop(i, n) FOR(i, 0, n)
#define sf scanf
#define pf printf
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define ll long long
#define dd double
#define all(v) v.begin(), v.end()
#define PI acos(-1.0)
#define mem(ara, value) memset(ara, value, sizeof(ara))
#define paii pair<int, int>
#define pall pair<ll, ll>
#define SZ(a) int(a.size())
#define read(nm) freopen(nm, "r", stdin)
#define write(nm) freopen(nm, "w", stdout)
#define dump(x) cout<<#x<<" = "<<x<<endl

using namespace std;

#define take(args...) asdf,args
#define debug(args...) asdfg,args; cout<<endl
struct ASDF{
    ASDF& operator,(int &a) {
        sf("%d", &a);
        return *this;
    }
    ASDF& operator,(long int &a){
        sf("%ld", &a);
        return *this;
    }
    ASDF& operator,(long long int &a){
        sf("%lld", &a);
        return *this;
    }
    ASDF& operator,(char &c){
        sf("%c", &c);
        return *this;
    }
    ASDF& operator,(double &d){
        sf("%lf", &d);
        return *this;
    }

    template<typename T>
    ASDF& operator,(T &a){
        cin>>a;
        return *this;
    }
}asdf;
struct ASDFG{
    template<typename T>
    ASDFG& operator,(vector<T> &v){
        pf("[");
        cout<<v[0];
        FOR(i, 1, SZ(v)){
            cout<<", "<<v[i];
        }
        pf("]");
        return *this;
    }

    template<typename T>
    ASDFG& operator,(T x) {
        cout<<x<<" ";
        return *this;
    }


}asdfg;



//Header ends here

int main()
{



    return 0;
}

গণনাযন্ত্র পূর্বলিখন (শুরুর কথা)

2

গণিতবিদ চার্লস ব্যাবেজ সাহেব যখন কম্পিউটার এর ধারণা দিয়েছিলেন তখন তিনি ভেবেছিলেন এই যন্ত্রখানা দিয়ে অনেক জটিল জটিল হিসাব নিকাশ খুব সহজে করা যাবে। তো তারপর অনেকগুলা বছর কেটে গেল। কম্পিউটার এর এত বেশী উন্নতি সাধন হল যে কম্পিউটার এর আসল উদ্দেশ্য থেকে আমরা যোজন যোজন দূরে গিয়ে শুধু মাত্র গেমস খেলা, মুভি দেখা, গান শোনাতেই মগ্ন থাকি। ব্যাপারটা বেশ পীড়াদায়ক!!! তাই চেষ্টা করব প্রোগ্রামিং এর শুরুর দিকের কিছু এখানে লিখে  রাখতে। তবে একটা জিনিস, এই ব্লগ টা পড়ে থেমে থাকবে না!! আমি শুধু দরজাটা দেখিয়ে দিতে পারি, দরজা খুলে করিডোরে হাঁটা, আর করিডোর এর সব দরজা খুলে দেখা তোমাদের দায়িত্ব!!!

তো প্রোগ্রামিং শেখার শুরু করার জন্য যে জিনিসটা লাগবে সেটা হল একটা কম্পাইলার। কম্পাইলার জিনিসটা অনেকটা দোভাষীর মতো কাজ করে। আগে কম্পিউটার এর সাথে কথা বলার জন্য মোটামুটি কম্পিউটার এর নিজের ভাষা(বাইনারি) এর কাছাকাছি কথা বলা লাগত। এখন প্রোগ্রামিং জিনিসটা অনেক বেশী সহজ হয়ে গিয়েছে। আমি এখানে সি++ ল্যাঙ্গুয়েজ টাই শিখানোর চেষ্টা করব। কারণ সি++ ল্যাঙ্গুয়েজ টা বোঝা খুব বেশী সহজ এবং সি/সি++ কেউ শেখার পর তার জন্য অন্য যেকোনো প্রোগ্রামিং ল্যাঙ্গুয়েজ শেখা খুব সহজ। আরেকটা কারণ ও কিন্তু আছে। দুনিয়ায় যত প্রোগ্রামিং কনটেস্ট আছে সবখানে মাত্র অল্প কয়েকটা ল্যাঙ্গুয়েজ ইউজ করতে দেয়!! বেশিরভাগ ক্ষেত্রেই সি, সি++ আর জাভা। এদের মধ্যে শুরু করার জন্য সি++ সবচেয়ে ভাল এবং সি++ তে কোড লিখলে কেমন যেন কনটেস্ট মুড আসে!! যেটা সবচেয়ে মজার!!

তো বেশীর ভাগ মানুষ ইউজ করে কোড ব্লক্স। এটা ওপেন কোর্স+ফ্রী সফটওয়্যার। সফটওয়্যার টা ফ্রী ডাউনলোড করা যাবে কোডব্লক্স এর অফিসিয়াল ওয়েবসাইট থেকে। আর যাদের কাছে এই মুহুর্তে কম্পিউটার নেই তারাও কিন্তু শিখতে পারো যদি ইন্টারনেট কানেকশন থাকে!! http://ideone.com/ এও কোড লিখতে পারো, কোন কিছু ডাউনলোড না করেই, আর ইচ্ছা করলে মোবাইল থেকেও কোড লিখতে পারবে এখনে!!! ইনস্টল করার পর ওপেন করে একটা নিউ empty ফাইল[ctrl+shift+N] বানাও। ফাইল টা যেকোনো জায়গায় hello.cpp নাম দিয়ে সেভ করে ফেলো। তারপর নিচের কোডটা হুবুহু লিখে ফেলো!!

#include<iostream>
using namespace std;
int main()
{
    cout<<"Hello World!!!"<<endl;
    return 0;
}

তারপর বিল্ড মেন্যুতে গিয়ে “বিল্ড অ্যান্ড রান” করেও!! যদি ঠিকভাবে লিখতে পারো তবে তোমার সামনে প্রোগ্রামিং এর কালো দুনিয়ার বাক্স ওপেন হয়ে বলবে ‘হ্যালো ওয়ার্ল্ড’!!! কোড টুকু কিভাবে কাজ করে সেটা পরের পর্বে বুঝাব। সে পর্যন্ত প্রোগ্রামিং এর কালো দুনিয়ায় স্বাগতম!!!