+ 2

Cake Challenge!

I wrote a little program which give me the number of pieces that can be obtained at most from a cake, making no more than N cuts. #include <iostream> #include <math.h> int main() { long long N; long long C; std::cin >> N; if(N < 0){ C = ((long long)(abs(N)/2 - 1) * (abs(N)/2 - 1)); } else if (N%2==0){ C = ((long long)(N/2 + 1) * (N/2 + 1)); } else if(N == 0){ C = 1; } else if(N % 2 != 0){ C = ((long long)(floor(N / 2) + 2) * (floor(N / 2) + 1)); } std::cout << C << std::endl; return 0; } It give me the correct answer except for 1 N which is? P.S. 0 <= N <= 1 000 000 000.

21st Feb 2018, 5:38 PM
Francesco Pippo
Francesco Pippo - avatar
5 Antworten
+ 1
The pieces are equal size and each cut is made either vertically or horizontally, for the whole length of the cake.
19th Feb 2018, 8:41 PM
Francesco Pippo
Francesco Pippo - avatar
+ 7
What are the assumptions. Are the pieces equal in size, i.e. all cuts go through the centre?
18th Feb 2018, 7:45 PM
Louis
Louis - avatar
+ 1
I'd love to hear your definition of a negativ cut. But getting 0 pieces of cake without cutting at all is quite odd ;)
18th Feb 2018, 9:02 PM
Merlin Mittelbach
+ 1
🤔 A complex piece of cake is a piece of cake that can be expressed in the form a + bi, where a and b are real pieces of cake, and i is a solution of the equation (cut² = −1), which is called an imaginary piece of cake because there is no real number that satisfies this equation. According to the fundamental theorem of delicous food, all desserts with real or complex cuts have a solution in complex pieces of cake. Not that hard @merlin 😒
21st Feb 2018, 6:58 PM
Alex
Alex - avatar
+ 1
this is my code in python: carrots = int(input()) boxes = int(input()) rem = carrots % boxes if rem >= 7: print("Cake Time") else: print("I need to buy " + str(7 - rem) + " more")
30th Dec 2022, 12:23 PM
Haroune
Haroune - avatar