本文主要是介绍codefoces 994,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
A. Fingerprints
水题,暴力
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define pb push_back
#define inf 0x3f3f3f3f
#define eps 1e-10
const int N = 3e5+10;int n,m,a[N],b[N];int main() {ios::sync_with_stdio(0);cin.tie(0);cin>>n>>m;vector<int> v;for(int i=1;i<=n;i++) cin>>a[i];for(int i=1;i<=m;i++) cin>>b[i];for(int i=1;i<=n;i++) {for(int j=1;j<=m;j++) {if(a[i]==b[j]) v.pb(a[i]);}}for(int i=0;i<v.size();i++) {cout<<v[i];if(i!=v.size()-1) cout<<" ";}return 0;
}
B. Knights of a Polygonal Table
模拟,用优先队列(小根堆)维护前k大值
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define pb push_back
#define inf 0x3f3f3f3f
#define eps 1e-10
const int N = 3e5+10;int n,k;struct nod {ll a,b;int id;
}p[N];
ll s[N];bool cmp(nod x,nod y) {return x.a<y.a;
}int main() {ios::sync_with_stdio(0);cin.tie(0);cin>>n>>k;for(int i=0;i<n;i++) cin>>p[i].a,p[i].id=i;for(int i=0;i<n;i++) cin>>p[i].b;sort(p,p+n,cmp);priority_queue<int, vector<int>, greater<int> > q;ll tp=0;s[0]=p[0].b;for(int i=1;i<n;i++) {q.push(p[i-1].b);tp+=p[i-1].b;if(q.size()>k) {ll tt=q.top();tp-=tt;q.pop();}s[i]=tp+p[i].b;}for(int i=0;i<n;i++) {cout<<s[p[i].id];if(i!=n-1) cout<<" ";}return 0;
}
C. Two Squares(给你两个正方形,判断有没有相交 )
暴力判断是否存在点位于两个正方形内
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
#define pb push_back
#define inf 0x3f3f3f3f
#define eps 1e-10
const int N = 3e5+10;struct nd{int x,y;
}p1[10],p2[10];bool cmp1(nd a,nd b) {if(a.y==b.y) return a.x<b.x;return a.y<b.y;
}bool cmp2(nd a,nd b) {if(a.x==b.x) return a.y<b.y;return a.x<b.x;
}int ss(nd a,nd b,nd c) {return abs((c.x-a.x)*(c.y-b.y)-(c.x-b.x)*(c.y-a.y));
}int main() {ios::sync_with_stdio(0);cin.tie(0);for(int i=0;i<4;i++) cin>>p1[i].x>>p1[i].y;for(int i=0;i<4;i++) cin>>p2[i].x>>p2[i].y;sort(p1,p1+4,cmp1);swap(p1[2],p1[3]);sort(p2,p2+4,cmp2);swap(p2[2],p2[3]);int S1=(p1[1].x-p1[0].x)*(p1[1].x-p1[0].x),S2=(p2[1].x-p2[0].x)*(p2[1].x-p2[0].x)+(p2[1].y-p2[0].y)*(p2[1].y-p2[0].y);int f=0;for(int i=-100;i<=100;i++) {for(int j=-100;j<=100;j++) {nd tp;tp.x=i,tp.y=j;int k=4,id=0,s1=0,s2=0;while(k--) {s1+=ss(p1[id%4],p1[(id+1)%4],tp);id++;}k=4,id=0;while(k--) {s2+=ss(p2[id%4],p2[(id+1)%4],tp);id++;}if(s1==2*S1 && s2==2*S2) f=1;}}if(f) cout<<"YES"<<endl;else cout<<"NO"<<endl;return 0;
}
这篇关于codefoces 994的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!