第一题:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n = 0;
int x, y;
int distance(int a, int b, int x, int y)
{
return (a – x) * (a – x) + (b – y) * (b – y);
}
int main()
{
vector<pair<int, int>> a;
scanf(“%d%d%d”, &n, &x, &y);
int k, h;
for (int i = 1; i <= n; i++)
{
scanf(“%d%d”, &k, &h);
a.push_back(make_pair(distance(k, h, x, y), i));
}
sort(a.begin(), a.end());
// for (int i = 0; i < 3; i++)
// printf(“%d\n”, a[i].second);
for (int i = 0; i < n; i++)
printf(“%d %d\n”, a[i].first, a[i].second);
return 0;
}
第二题:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, k, t, xl, yd, xr, yu;
int sum_pass = 0, sum_stop = 0;
int in_out(int x, int y)
{
if (x >= xl && x <= xr && y >= yd && y <= yu)
return 1;
return 0;
}
// ,int xl,int yd,int xr,int yu
int main()
{
int cnt_pass = 0, cnt_stop = 0, cnt = 0;
int x, y;
scanf(“%d %d %d %d %d %d %d”, &n, &k, &t, &xl, &yd, &xr, &yu);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < t; j++)
{
cin >> x >> y;
if (in_out(x, y))
{
cnt_pass++;
cnt_stop++;
if (cnt_stop >= k)
cnt = 1;
}
else
cnt_stop = 0;
}
if (cnt_pass > 0)
sum_pass++;
if (cnt == 1)
sum_stop++;
cnt_pass = cnt_stop = cnt = 0;
}
printf(“%d\n%d”, sum_pass, sum_stop);
return 0;
}
水得一