2015年3月2日月曜日

KODER COMBAT : Divide It

Problem

https://www.hackerrank.com/contests/koder-kombat-mar/challenges/divide-it

Solution

When we used i segments and got t-divided paper and add a new segment to it , we can get k new intersections(k=0,1,...,i-1) and t+i+1-divided paper.
Let (t,i) is a state of t-divided paper using i segments.
Then, (t,i) -> (t+1,i+1) , (t+2,i+1) , ... (t+i-1,i+1).


Code

int main() {
    int t;cin>>t;
    while(t--){
        int m;cin>>m;
        for(int i=0;i<m;++i){
            if(1+i*(i+1)/2>=m){
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

0 件のコメント:

コメントを投稿

情報理論と加法的組合せ論の交差点: Changの不等式

概要 加法的組合せ論における基本的な定理の一つとして, Changの不等式と呼ばれるものがあります. これは, ベクトル空間 $\mathbb{F}_2^n$ の部分集合 $A\subseteq \mathbb{F}_2^n$ に対し, その指示関数の各フーリエ係数を見たとき, ...