H. 杰哥抓气球

题解

明显,处于 (0,0)(0,0) 的点不需要任何代价。

如果点到原点的距离为整数,则代价为 22,比如 (3,4)(3,4)(0,5)(0,5)。否则,任何点都可以通过走平行于 x,yx,y 轴的直线到达,只需要两步,一去一来代价为 44。例如 (7,8)(7,8) 可以通过 (0,0)(0,7)(7,8)(0,0) \to (0,7)\to (7,8) 来实现。

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))
则可以过
*/