202009-1(称检测点查询)
题目链接:
计算机软件能力认证考试系统http://118.190.20.162/view.page?gpid=T113题意:
思路:
利用结构体排序即可。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<cmath>
#include<unordered_set>
#define PII pair<int, int>
#define ll long long
using namespace std;
const int N = 210;
int n, x, y;
struct pt
{
int num, a, b;
double dis;
} poit[N];
bool cmp(pt p1, pt p2)
{
if(p1.dis != p2.dis)return p1.dis < p2.dis;
else return p1.num < p2.num;
}
void solve()
{
cin >> n >> x >> y;
for (int i = 1; i <= n; ++ i)
{
poit[i].num = i;
cin >> poit[i].a >> poit[i].b;
poit[i].dis = pow(x - poit[i].a, 2) + pow(y - poit[i].b, 2);
}
sort(poit + 1, poit + n + 1, cmp);
for (int i = 1; i <= 3; ++ i) cout << poit[i].num << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// int T;
// cin >> T;
//
// while(T--)
// {
solve();
// }
return 0;
}
202009-2(风险人群筛查)
题目链接:
计算机软件能力认证考试系统http://118.190.20.162/view.page?gpid=T112
题意:
思路:
本题就是一个逐一判断坐标是否位于“高危”区内,如果有一次位于过,那么就是经过,如果连续处于超过k,那就是逗留,比较坑的点在于必须是连续的处于才算,所以只需要设置一个is的布尔变量来判断就行,每次连续的开头将is置true,结尾将is置false并且更新最大连续数,最后根据k判断即可。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<stack>
#include<cmath>
#include<unordered_set>
#define PII pair<int, int>
#define ll long long
using namespace std;
const int N = 110;
int n, k, t, xl, yd, xr, yu;
int x, y;
int guo, liu;
void solve()
{
cin >> n >> k >> t >> xl >> yd >> xr >> yu;
int sum = 0, ma = 0;
for (int op = 0; op < n; ++ op)
{
ma = 0, sum = 0;
bool is = false;
for (int i = 0; i < t; ++ i)
{
cin >> x >> y;
if(x >= xl && x <= xr && y >= yd && y <= yu)
{
if(!is)
{
is = true;
sum = 0;
}
++ sum;
}
else
{
ma = max(ma, sum);
is = false;
}
}
ma = max(sum, ma);
if(ma > 0 && ma < k) guo ++;
else if(ma >= k) guo ++, liu ++;
}
cout << guo << endl;
cout << liu << endl;
}
signed main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// int T;
// cin >> T;
//
// while(T--)
// {
solve();
// }
return 0;
}