题目链接:QAQ
题意:一直小青蛙位于标号为0的荷叶,他要跳到标号为200的荷叶,他每次只能想右跳一格或者两格,现在有传送门,如果x号的荷叶上建着传送门,如果小青蛙到达x位置,就必须传送到传送门指定的位置,一个荷叶上只能建一个传送门的起点。题目中指出如果没有传送门,小青蛙跳到每个荷叶的方案数符合斐波那契数列(其实并没有什么卵用)。现在给你一个到终点的方案数,让你构造传送门。
思路:唉,比赛的时候太紧张了,一直按着错误的方向想,这该死的斐波那契数列。
(用二进制进行构造)其实构造的操作差不多都想到了,就是没想到一起实现。
详细构造方法见代码。
附上代码
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
struct inst {
int x;
int y;
};
inst ax[300];
int main(void) {
long long n;
while (scanf("%lld", &n) != EOF) {
if (n == 0) {
printf("2\n");
printf("1 1\n");
printf("2 1\n");
continue;
}
else if (n == 1) {
printf("2\n");
printf("1 199\n");
printf("2 2\n");
continue;
}
int t = 0;
int cnt = 0;
while (n != 1) {
int z = n % 2;
if (z == 1) {
n = n - 1;
ax[cnt].x = t+1;
ax[cnt].y = 199;
cnt++;
t = t + 2;
}
else {
n = n / 2;
ax[cnt].x = t + 1;
ax[cnt].y = t + 3;
cnt++;
ax[cnt].x = t + 2;
ax[cnt].y = t + 1;
cnt++;
t = t + 3;
}
}
ax[cnt].x = t;
ax[cnt].y = 199;
cnt++;
printf("%d\n", cnt);
for (int i = 0; i < cnt; i++) {
printf("%d %d\n", ax[i].x, ax[i].y);
}
}
return 0;
}