Codeforces gym 101149 G 想法
来源:互联网 发布:数据库安全性论文 编辑:程序博客网 时间:2024/05/21 21:40
Zorcs don't like other species. Zorcs like massive curve axes. Right now each of them is going to choose a suitable axe and show beings of other races entrenched nearby that they are not ready to peaceful cultural assimilation. There are n zorcs and m axes in total, and the i-th zorc wants to take an axe with the weight not less than ai and the curvature not less than bi, while the j-th axe has the weight wjand the curvature cj. Zorcs don't like programming problems. Zorcs like massive curve axes. So it's your task to determine which zorc must choose which axe.
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of zorcs.
Each of the next n lines contains two space-separated integers: ai and bi (1 ≤ ai, bi ≤ 109) — the minimal weight and curvature of the axe that suits the i-th zorc.
The next line contains a single integer m (1 ≤ m ≤ 2·105) — the number of axes.
Each of the next m lines contains two space-separated integers: wj and cj (1 ≤ wj, cj ≤ 109) — the weight and the curvature of the j-th axe.
Output n integers, the i-th of which must be the number of axe that should be given to the i-th zorc to fulfill all his requirements. Of course, the same axe can't be given to two different zorcs.
If there is no possibility to distribute axes, fulfilling all requirements of all zorcs, output a single number - 1 instead of that.
33 45 12 645 74 53 35 2
2 4 1
22 54 325 63 4
-1
题意:给你n对数 m对数 找出对应的下标 使得n[i]的x和y都小于等于m[i]的x和y 输出方案 不存在输出-1
题解:将n和m都从大到小排序 然后for n 对于每个n 将大于等于当前对x的m全部加到set里面 然后随便找一个my比当前y大的即可 如果不存在 -1
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<set>using namespace std;struct node{int x,y,lab;bool operator<(const node& a)const{if(x==a.x&&y==a.y)return lab<a.lab;if(x==a.x)return y>a.y;return x>a.x;}}e[200005],e1[200005];int ans[200005];struct nodes{int y,lab;bool operator<(const nodes& a)const{if(y==a.y)return lab<a.lab;return y<a.y;}};multiset<nodes>sp;multiset<nodes>::iterator it,it1;int main(){int n,m,i,j,num,flag=1;scanf("%d",&n);for(i=1;i<=n;i++){scanf("%d%d",&e[i].x,&e[i].y);e[i].lab=i;}sort(e+1,e+1+n);scanf("%d",&m);for(i=1;i<=m;i++){scanf("%d%d",&e1[i].x,&e1[i].y);e1[i].lab=i;}sort(e1+1,e1+1+m);nodes f;int now=1;for(i=1;i<=n;i++){while(e1[now].x>=e[i].x&&now<=m){f.y=e1[now].y;f.lab=e1[now].lab;sp.insert(f);now++;}f.y=e[i].y;f.lab=e[i].lab;sp.insert(f);it=sp.find(f);it1=sp.end();it1--;if(it==it1){if(it!=sp.begin()){it--;if((*it).y>=f.y){ans[f.lab]=(*it).lab;sp.erase(it);it1=sp.find(f);sp.erase(it1);}else{flag=0;break;}}else{flag=0;break;}}else{if(it!=sp.begin()){it--;if((*it).y>=f.y){ans[f.lab]=(*it).lab;sp.erase(it);it1=sp.find(f);sp.erase(it1);}else{it++;it++;ans[f.lab]=(*it).lab;sp.erase(it);it1=sp.find(f);sp.erase(it1);}}else{it++;ans[f.lab]=(*it).lab;sp.erase(it);it1=sp.find(f);sp.erase(it1);}}}if(!flag)printf("-1\n");else{for(i=1;i<=n;i++)printf("%d ",ans[i]);printf("\n");}return 0;}
- Codeforces gym 101149 G 想法
- Codeforces gym 101149 K 想法
- Codeforces gym 101350F 想法
- Codeforces gym 101102 K 想法
- codeforces gym 100548G
- CodeForces Gym 100735G
- CodeForces Gym 100735G
- Codeforces-GYM-100923G
- codeforces [Gym-100814G]
- Codeforces Gym-101617G
- Codeforces gym 101350G 数学
- Codeforces Gym 101164 G. Pokemons
- Codeforces Gym 100625G Getting Through
- codeforces Gym 100431G Persistent Queue
- Codeforces Gym 100543G Virus synthesis
- CodeForces Gym 100646G The Worm Turns
- 【模拟】NEERC15 G Generators (Codeforces GYM 100851)
- [Codeforces Gym] 100162G 爆搜+剪枝
- Java——命令jps、jstat、jmap、jstack、jhat、jinfo
- Android系统客制化信号标准
- ZOJ 3960 What Kind of Friends Are You?【】
- 移动设备user_agent
- google c++ 编码规范
- Codeforces gym 101149 G 想法
- java(三)
- 39. Combination Sum
- ButterKnife注解使用配置
- hdu4608_I-number_高精度+暴力
- RHCSA-EXERCISE
- 电商平台结构图
- 设置VMWARE通过桥接方式使用主机无线网卡上网
- 186_08_IO流_FileInputStream__06_available_skip方法