题解 | #炮台攻击# C++
炮台攻击
https://www.nowcoder.com/practice/f821a39207cd43518ccddb27fee0481d
#include <iostream> #include <cmath> #include <vector> using namespace std; int main() { int R; //炮台攻击半径 while(cin >> R){ vector<vector<int>> tanks; vector<int> tank(2); for(int i=0; i<3; i++){ //存入三个炮台的坐标 cin >> tank[0] >> tank[1]; tanks.push_back(tank); } vector<int> enemy(2); cin >> enemy[0] >> enemy[1]; //存入敌人坐标 int damage = 0; for(vector<int> temp : tanks){ //遍历每个炮台 int x1 = temp[0], y1 = temp[1]; int x2 = enemy[0], y2 = enemy[1]; double len = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)); if(len <= R) damage++; } cout << damage << 'x' << endl; } return 0; } // 64 位输出请用 printf("%lld")