H. 杰哥抓气球
题解
明显,处于 的点不需要任何代价。
如果点到原点的距离为整数,则代价为 ,比如 和 。否则,任何点都可以通过走平行于 轴的直线到达,只需要两步,一去一来代价为 。例如 可以通过 来实现。
std:
#include<bits/sdc++.h>
using namespace std;
int main() {
int t,ans=0;
cin >> t;
while (t--) {
int x, y; cin >> x >> y;
if (x == 0 && y == 0)continue;
int d = x * x + y * y,r=0;
while (r * r < d)r++;
if (r * r == d)ans+=2;
else ans += 4;
}
cout << ans << endl;
}
/*
注意,此题可以用sqrt判断勾股数
但是要注意使用正确的写法
这种写法
if(sqrt(x*x+y*y) * sqrt(x*x+y*y) == x*x+y*y) ans += 2;
会wa
必须要把开方后的double转换成int再进行比较
例如
int temp = sqrt(all);
int(sqrt(x * x + y * y))
则可以过
*/