2021.1.28 题解 + 补题
比赛链接:https://codeforces.com/contest/994
A题:https://codeforces.com/contest/994/problem/A
题意:挨个判断A中的数字是否在B中存在,如果存在就输出
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL t,n,m;
const int N = 1e6 + 10;
int a[N];
int b[N];
int main()
{
cin >> n >> m;
for(int i = 0;i < n;i ++)
cin >> a[i];
for(int i = 0;i < m;i ++){
int x;
cin >> x;
b[x] = 1;
}
for(int i = 0;i < n;i ++){
if(b[a[i]]){
cout << a[i] << ' ';
}
}
return 0;
}
B题:https://codeforces.com/contest/994/problem/B
题意:每个骑士可以杀死比自己攻击力小的人,但是每个骑士最多能杀k个人,问你每个骑士最后能获得的硬币的最大数量(如果你杀死一个骑士,你就可以获得它的所有硬币)
- 优先队列的简单应用 + 简单排序
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL t,n,m;
const LL N = 1e6 + 10;
struct edge{
LL id;
LL p;
LL c;
}f[N];
LL sum[N];
LL ans[N];
int main()
{
cin >> n >> m;
for(LL i = 0;i < n;i ++){
cin >> f[i].p;
f[i].id = i;
}
for(LL i = 0;i < n;i ++){
cin >> f[i].c;
}
sort(f,f+n,[](edge e1,edge e2){
return e1.p < e2.p;
});
priority_queue<LL>q;
for(LL i = 0;i < n;i ++){
LL bm = m;
vector<LL> v;
sum[i] = f[i].c;
while(q.size() && m){
LL t = q.top();
v.push_back(t);
sum[i] += t;
m --;
q.pop();
}
if(m == 0){
while(q.size()){
q.pop();
}
}
for(auto &x : v){
q.push(x);
}
m = bm;
q.push(f[i].c);
}
for(LL i = 0;i < n;i ++){
ans[i] = sum[f[i].id];
}
for(LL i = 0;i < n;i ++){
cout << ans[i] << ' ';
}
return 0;
}
补题:
C题:https://codeforces.com/contest/994/problem/C
题意: 就是判断两个正方形是否相交,如果一个正方形把另一个包含也算是相交,也就是问这两个正方形是否有重合的部分
- 直接判断45°的那个正方形边上的点是否在与x轴平行的那个正方形里,最后还得判断一下,中心是否在另一个正方形里,就OK了
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL t,n,m;
const int N = 1e6 + 10;
int xl = 110,xr = -110,yu = -110,yd = 110;
typedef pair<int,int> PII;
PII p[5];
bool check(int x,int y){
if(x >= xl && x <= xr && y >= yd && y <= yu){
return true;
}
return false;
}
int main()
{
int n = 4;
for(int i = 0,x,y;i < n;i ++){
cin >> x >> y;
xl = min(xl,x);
xr = max(xr,x);
yu = max(yu,y);
yd = min(yd,y);
}
for(int i = 0;i < n;i ++){
cin >> p[i].first >> p[i].second;
}
sort(p,p + n,[](PII p1,PII p2){
if(p1.first == p2.first){
return p1.second < p2.second;
}
return p1.first < p2.first;
});
// 1、 k = -1
for(int i = p[0].first;i <= p[1].first;i ++){
if(check(i,-i + p[0].first + p[0].second)){
cout << "YES" << endl;
return 0;
}
}
// 2. k = 1
for(int i = p[0].first;i <= p[2].first;i ++){
if(check(i,i - p[0].first + p[0].second)){
cout << "YES" << endl;
return 0;
}
}
// 3. k = -1
for(int i = p[2].first;i <= p[3].first;i ++){
if(check(i,-i + p[2].first + p[2].second)){
cout << "YES" << endl;
return 0;
}
}
// 4. k = 1
for(int i = p[1].first;i <= p[3].first;i ++){
if(check(i,i - p[1].first + p[1].second)){
cout << "YES" << endl;
return 0;
}
}
if(check(p[1].first,p[0].second)){
cout << "YES" << endl;
return 0;
}
cout << "NO" << endl;
return 0;
}
知足常乐!