题解:P11055 Yet another ZP problem
P11055 Yet another ZP problem
题意分析
根据题目名称我们可知这是一道诈骗题,存在一种构造可以通过所有数据。
30pts
我们分析样例可以得出第一行输出的数是
记得 特判 奇数哦。
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
scanf("%d", &n);
printf("%d\n", (n + 1) / 2);
for (int i = 1; i <= n / 2; i++) {
printf("%d %d\n", i, n + 1 - i);
}
if (n % 2 == 1)
puts("1 n");
return 0;
}
AC正解
由于上面的代码只能得30分,所以我们需要一个AC代码 我们需要一开始就特判奇偶。
#include <bits/stdc++.h>
using namespace std;
int n;
int mian() { // 意会
scanf("%d", &n);
printf("%d\n", (n + 1) / 2);
if (n % 2 == 1) {
for (int i = 1; i <= n / 2; i++) {
printf("%d %d\n", i, n + 1 - i);
}
printf("%d %d\n", 1, n / 2 + 1);
} else {
printf("%d %d\n", 1, n / 2 + 1);
for (int i = 2; i <= n / 2; i++) {
printf("%d %d\n", i, n + 2 - i);
}
}
return 0;
}
建议评绿。