题解 P7573 【「PMOI-3」公平正义】

· · 题解

首先我们发现,切一刀蛋糕一定只能增加两块蛋糕。

那么,如果 n\equiv 0\pmod{2},就只需要切 \frac{n}{2}=\left\lfloor\frac{n+1}{2}\right\rfloor 刀蛋糕。

讨论完这些情况,我们只能得到 $40$ 分。我们还有 $n=1$ 的情况没讨论,$n=1$ 时一刀也不用切,输出 $0$,但我们的代码会输出 $1$。这种情况特判一下就好了。 代码: ```cpp #include <cstdio> using namespace std; int t,n; int main(){ scanf("%d",&t); while(t--){ scanf("%d",&n); printf("%d\n",n==1?0:n+1>>1); } return 0; } ```