C01-结构体练习(10.26)
原题链接:83310.xiaochenxuanNote2025-10-26 20:23:27
发布于:江苏

#include <bits/stdc++.h>
using namespace std;
struct node {//自定义的结构体类型 
	int x, y, flag; 
}a[1010];
int cnt;
//返回距离函数 
int get_distance(int x, int y, int z, int w){
	return sqrt((x-z)*(x-z) +  (y-w)*(y-w));
} 
int main() {
	int n, x, y, k, t;
	cin >> n >> k >> t; 
	//1.n个密码机 
	for (int i=1; i<=n; i++){
		cin >>a[i].x>>a[i].y;
	}
	//2.k个出生密码机 
	for(int i=1; i<=k; i++){
		cin >> x >> y;		//出生密码机
		for (int j=1; j<=n; j++){
			if (x == a[j].x && y == a[j].y) 
				a[j].flag = true;	//标记出生密码机 
		}
	} 
	//3.t个出生点 (攻击点)产生t个 封禁 
	for (int i=1; i<=t; i++){
		cin >> x >> y;
		int cur_dis = -1, ans; 
		for (int j=1; j<=n; j++){
			int dis = get_distance(x, y, a[j].x, a[j].y); 
			if (dis > cur_dis){
				cur_dis = dis; 
				ans = j; 
			}
		} 
		//判断封禁的那台密码机是不是出生密码机 
		if (a[ans].flag == 1){
			cnt++;
		}
	}
	cout << cnt; 
	return 0;
}
/*
输入: 
4 2 2 
-1 0
0 -1
2 0
0 2 
-1 0
0 2
3 0
0 0 
输出:1 
*/
这里空空如也









有帮助,赞一个