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 件のコメント:

コメントを投稿

凸共役と集中不等式

 凸解析のツールの一つとして凸共役という概念があります. $I\subseteq \mathbb{R}$上で定義された実関数$f$の凸共役とは \[ f^*(a) = \sup_{x\in I}\{ax - f(x)\} \] で定義されます. 通常は$I=\mathbb{R}$...