跳到正文

题解

题解:P11055 Yet another ZP problem

可爱大黄兔约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年9月16日
收录
2025年12月12日
更新
2026年11月21日
篇幅
约 2 分钟
题目
P11055

版本

  1. v1当前

P11055 Yet another ZP problem

题意分析

根据题目名称我们可知这是一道诈骗题,存在一种构造可以通过所有数据。

30pts

我们分析样例可以得出第一行输出的数是 (n+1)/2(n+1)/2 接下来 (n/2)(n/2) 行是 ii,(i+1)(i+1)。

记得 特判 奇数哦。

C++
#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代码 我们需要一开始就特判奇偶。

C++
#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;
}

建议评绿。

原文