Let‘s bust the "level" 0 ≤ i ≤ 106,
in which assumedly the stone could hit. Let’s find the minimal number
of square on this level. Then we can understand, how many squares there
are on this level: one or two. Then we check with one or two ifs (if on
this level two squares) if the stone is in corresponding square or not.
If the stone is inside then output the answer. If we didn‘t find any
square, where the stone is, output "-1".
官方的意思大概是 106 级别,一个一个枚举过去(好吧,博主英文不行,胡诌的);
一开始只看到图示,以为最多到 7 (至于1-1-2-1...,不知道是什么),就一直 WA
直到 ....
看懂题目后,果断加上这几句
tmp = 0; while (y > 5 * a) tmp += 3, y -= 2 * a; printf("%d\n", calculate(a, x, y) + tmp * (calculate(a, x, y) != -1));
层数 > 7 ,纵坐标 -2*a , 序号 -3 (前提自然是在格子内),然后 .....
居然就 A 了。
#include<bits/stdc++.h> int f[16]; int calculate(int a, int x, int y); int main() { int a, x, y, tmp; f[1] = 1; for (int i = 2; i < 8; i++) f[i] = f[i - 1] + 1; while (~scanf("%d%d%d", &a, &x, &y)) { tmp = 0; while (y > 5 * a) tmp += 3, y -= 2 * a; printf("%d\n", calculate(a, x, y) + tmp * (calculate(a, x, y) != -1)); } return 0; } int calculate(int a, int x, int y) { if (x < (a + 1) / 2 && x > -(a + 1) / 2 && y > 0 && y < a) return f[1]; if (x < (a + 1) / 2 && x > -(a + 1) / 2 && y > a && y < 2 * a) return f[2]; if (x < 0 && x > -a && y > 2 * a && y < 3 * a) return f[3]; if (x > 0 && x < a && y > 2 * a && y < 3 * a) return f[4]; if (x < (a + 1) / 2 && x > -(a + 1) / 2 && y > 3 * a && y < 4 * a) return f[5]; if (x < 0 && x > -a && y > 4 * a && y < 5 * a) return f[6]; if (x > 0 && x < a && y > 4 * a && y < 5 * a) return f[7]; else return -1; }
时间: 2024-10-02 08:56:37