题解 | #炮台攻击# 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")

全部评论

相关推荐

07-07 14:30
复旦大学 Java
遇到这种人我也不知道说啥了
无能的丈夫:但我觉得这个hr语气没什么问题啊(没有恶意
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务