題目鏈接:Codeforces 468A 24 Game
題目大意:給出n,表示有1~n這n個數,判斷能否進n-1次操作獲得24.
解題思路:4,5的情況可以手動處理出來,然後對於大於4,5的情況可以通過兩兩相減,形成若干個1.
#include
#include
#include
using namespace std;
int main () {
int n;
scanf("%d", &n);
if (n < 4)
printf("NO\n");
else {
printf("YES\n");
if (n&1) {
printf("4 * 5 = 20\n");
printf("20 + 3 = 23\n");
printf("23 + 2 = 25\n");
printf("25 - 1 = 24\n");
for (int i = 6; i <= n; i += 2) {
printf("%d - %d = 1\n", i + 1, i);
printf("24 * 1 = 24\n");
}
} else {
int c = 1;
for (int i = 2; i <= 4; i++) {
printf("%d * %d = %d\n", c, i, c * i);
c = c * i;
}
for (int i = 5; i <= n; i += 2) {
printf("%d - %d = 1\n", i + 1, i);
printf("24 * 1 = 24\n");
}
}
}
return 0;
}