Game Code Network programming exercise (iv)

Source: Internet
Author: User

Hemmedinger's Fort.

Title Description

After Rambo taught Titus, and then talked with Timothy about the people of the Hemmedinger, talking about the people of the Covenant, there was one man, the greatest scientist in the history of the German people.

Mo said, Hemmedinger recently thinking about a problem: Hemmedinger has three turrets, the fort can attack the enemy from its R, (two points between the distance of two points, such as the distance between (3,0) and (0,4) is 5), if a fort can attack the enemy, then the enemy will cause 1 x damage. Hemmedinger placed three forts on the points in the N*m Square and gave the enemy coordinates.

Q: How big will the enemy be harmed?

Input: The first line of 9 integers, r,x1,y1,x2,y2,x3,y3,x0,y0. (0 <= r,x1,y1,x2,y2,x3,y3,x0,y0 <= 100) R represents the maximum distance of the battery attack, (x1,y1), (X2,y2), (X3,Y3) represents the coordinates of three turrets. (X0,y0) represents the enemy's coordinates.

Output:

The output line, which represents the maximum damage the enemy can withstand (if each turret cannot attack the enemy, output 0X). The output format is shown in the sample example.

example input

1 1 1 2 2 3 3 1 2

example output

2 x

This problem is relatively simple, here directly to the code:

#include"stdafx.h"#include<stdio.h>#include<iostream>#include<algorithm>#include<math.h>using namespaceStd;typedefstructcannon{intx, y; intR;} Cannon;typedefstructtarget{intx, y;} Target;DoubleCalculate_dis (Cannon m, Target N) {Doubledist = sqrt ((m.x-n.x) * (m.x-n.x) + (M.Y-N.Y) * (M.Y-N.Y)); returnDist;}intMain () {Cannon A, B, C;    Target D; intI=0; intR; intCnt=0; intdata[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]; DoubleDist_ad =Calculate_dis (A, D); DoubleDIST_BD =Calculate_dis (b, D); DoubleDIST_CD =Calculate_dis (c, D); if(Dist_ad <= R) cnt++; if(DIST_BD <= R) cnt++; if(Dist_cd <= R) cnt++; printf ("%dx\n", CNT);}

Game Code Network programming exercise (iv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.