赛码网编程练习(四)

黑默丁格的炮台

题目描述

兰博教训了提莫之后,然后和提莫讨论起约德尔人,谈起约德尔人,自然少不了一个人,那就是黑默丁格——约德尔人历史上最伟大的科学家。

提莫说,黑默丁格最近在思考一个问题:黑默丁格有三个炮台,炮台能攻击到距离它R的敌人,(两点之间的距离为两点连线的距离,例如(3,0)和(0,4)之间的距离是5),如果一个炮台能攻击到敌人,那么会对敌人造成1X的伤害。黑默丁格将三个炮台放在N*M方格中的点上,并且给出敌人的坐标。

问:那么敌人受到伤害会是多大?

输入:第一行9个整数,R,x1,y1,x2,y2,x3,y3,x0,y0。(0 <= R,x1,y1,x2,y2,x3,y3,x0,y0 <= 100) R 代表炮台攻击的最大距离,(x1,y1), (x2,y2), (x3,y3)代表三个炮台的坐标。(x0,y0)代表敌人的坐标。

输出:

输出一行,这一行代表敌人承受的最大伤害,(如果每个炮台都不能攻击到敌人,输出0X)。输出格式见样例。

样例输入

1 1 1 2 2 3 3 1 2

样例输出

2X

此题比较简单,这里直接给出代码:

#include"stdafx.h"
#include<stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef struct cannon{
    int x, y;
    int R;
}Cannon;
typedef struct target{
    int x, y;
}Target;
double calculate_dis(Cannon m, Target n){
    double dist = sqrt((m.x - n.x)*(m.x - n.x) + (m.y - n.y)*(m.y - n.y));
    return dist;
}
int main()
{
    Cannon a, b, c;
    Target d;
    int i=0;
    int R;
    int cnt=0;
    int data[9];
    while (scanf_s("%d",&data[i]) != EOF&& i<8){
        i++;
    }

    R = data[0];
    a.R = R;
    a.x = data[1];
    a.y = data[2];
    b.R = R;
    b.x = data[3];
    b.y = data[4];
    c.R = R;
    c.x = data[5];
    c.y = data[6];
    d.x = data[7];
    d.y = data[8];
    double dist_ad = calculate_dis(a, d);
    double dist_bd = calculate_dis(b, d);
    double dist_cd = calculate_dis(c, d);
    if (dist_ad <= R) cnt++;
    if (dist_bd <= R)cnt++;
    if (dist_cd <= R)cnt++;
    printf("%dX\n", cnt);
}

 

posted @ 2016-08-08 10:56  沐雨橙风fire  阅读(899)  评论(0编辑  收藏  举报