#include <bits/stdc++.h>
using namespace std;
class Solution {
private:
// 计算最大公约数
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public:
int calculateDamage(int R, vector<pair<int, int>>& turrets, pair<int, int>& enemy) {
int damage = 0;
for (auto& turret : turrets) {
// 计算炮台与敌人之间的距离
double distance = sqrt(pow(turret.first - enemy.first, 2) + pow(turret.second - enemy.second, 2));
// 如果距离小于等于R,炮台可以攻击敌人
if (distance <= R) {
damage += 1; // 每个炮台对敌人造成1点伤害
}
}
return damage;
}
};
int main() {
int R, x1, y1, x2, y2, x3, y3, x0, y0;
while (cin >> R >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x0 >> y0) {
vector<pair<int, int>> turrets = {{x1, y1}, {x2, y2}, {x3, y3}};
pair<int, int> enemy = {x0, y0};
Solution solution;
int damage = solution.calculateDamage(R, turrets, enemy);
cout << damage << "x" << endl; // 输出结果
}
return 0;
}
import java.util.Scanner;
public class Main {
static class Solution {
// 计算最大公约数
private int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public int calculateDamage(int R, int[][] turrets, int[] enemy) {
int damage = 0;
for (int[] turret : turrets) {
// 计算炮台与敌人之间的距离
double distance = Math.sqrt(Math.pow(turret[0] - enemy[0], 2) + Math.pow(turret[1] - enemy[1], 2));
// 如果距离小于等于R,炮台可以攻击敌人
if (distance <= R) {
damage += 1; // 每个炮台对敌人造成1点伤害
}
}
return damage;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int R = sc.nextInt();
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
int x3 = sc.nextInt();
int y3 = sc.nextInt();
int x0 = sc.nextInt();
int y0 = sc.nextInt();
int[][] turrets = {{x1, y1}, {x2, y2}, {x3, y3}};
int[] enemy = {x0, y0};
Solution solution = new Solution();
int damage = solution.calculateDamage(R, turrets, enemy);
System.out.println(damage + "x"); // 输出结果
}
sc.close();
}
}
import math
def calculate_damage(R, turret_positions, enemy_position):
damage = 0
for (x_t, y_t) in turret_positions:
# 计算炮台与敌人之间的距离
distance = math.sqrt((x_t - enemy_position[0]) ** 2 + (y_t - enemy_position[1]) ** 2)
# 如果距离小于等于R,炮台可以攻击敌人
if distance <= R:
damage += 1 # 每个炮台对敌人造成1点伤害
return damage
if __name__ == "__main__":
# 读取输入
while True:
try:
line = input().strip()
if not line: # 如果是空行就退出
break
# 解析输入
R, x1, y1, x2, y2, x3, y3, x0, y0 = map(int, line.split())
turret_positions = [(x1, y1), (x2, y2), (x3, y3)]
enemy_position = (x0, y0)
# 计算敌人受到的最大伤害
damage = calculate_damage(R, turret_positions, enemy_position)
print(f"{damage}x") # 输出结果
except EOFError:
break
except ValueError:
print("Error: Invalid input format.")
continue