Problem
https://www.hackerrank.com/contests/koder-kombat-mar/challenges/divide-itSolution
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 件のコメント:
コメントを投稿