Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // i try to solve this problem ^^ if i wrong, dont laugh me :)
- // We easy see that if n = 1 we dont need to cut and ans is 0
- // if n = 2 we need 1 cut
- // i call a[i] is the number of cut to make cake to i people.
- // now if n is a odd number we need 1 cut to make the cake in 2 side (n-1)/n and 1/n
- // now we need to share (n-1)/n cake to n-1 people (n-1) now is even. we habe a[n] = a[n-1] + 1;
- // if n is a even number, we need 1 cut to make the cake in 2 same side so a[n] = a[n/2] + 1;
- // It's code
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <cstring>
- #include <cmath>
- using namespace std;
- int n, m, i, j, a[100009];
- int main() {
- cin >> n; // cin n people
- a[1] = 0; // if n = 1 we need 0 cut
- a[2] = 1; // if n = 2 we need 1 cut
- for(i = 3; i <= n; i++){ // make a sequence a[i] is the answer of i people
- if(i % 2 == 1){ // if people is odd
- a[i] = a[i - 1] + 1;
- }
- else{ // if people is even
- a[i] = a[i / 2] + 1;
- }
- }
- cout << a[n] << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment