热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Codeforcesgym101149G想法

OfZorcsandAxestimelimitpertest2seconds

Of Zorcs and Axes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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

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.

Examples
input
3
3 4
5 1
2 6
4
5 7
4 5
3 3
5 2
output
2 4 1
input
2
2 5
4 3
2
5 6
3 4
output
-1

题意:给你n对数  m对数  找出对应的下标  使得n[i]的x和y都小于等于m[i]的x和y  输出方案  不存在输出-1


题解:将n和m都从大到小排序  然后for n  对于每个n  将大于等于当前对x的m全部加到set里面  然后随便找一个my比当前y大的即可  如果不存在 -1


#include
#include
#include
#include
#include
using namespace std;
struct node{
	int x,y,lab;
	bool operator<(const node& a)const{
		if(x==a.x&&y==a.y)return laba.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 labsp;
multiset::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;
}



推荐阅读
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • 本文介绍了Codeforces Round #321 (Div. 2)比赛中的问题Kefa and Dishes,通过状压和spfa算法解决了这个问题。给定一个有向图,求在不超过m步的情况下,能获得的最大权值和。点不能重复走。文章详细介绍了问题的题意、解题思路和代码实现。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了一个数列求和问题,该数列按照一定规律生成。通过观察数列的规律,我们可以得出求解该问题的算法。具体算法为计算前n项i*f[i]的和,其中f[i]表示数列中有i个数字。根据参考的思路,我们可以将算法的时间复杂度控制在O(n),即计算到5e5即可满足1e9的要求。 ... [详细]
  • 李逍遥寻找仙药的迷阵之旅
    本文讲述了少年李逍遥为了救治婶婶的病情,前往仙灵岛寻找仙药的故事。他需要穿越一个由M×N个方格组成的迷阵,有些方格内有怪物,有些方格是安全的。李逍遥需要避开有怪物的方格,并经过最少的方格,找到仙药。在寻找的过程中,他还会遇到神秘人物。本文提供了一个迷阵样例及李逍遥找到仙药的路线。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • 本文介绍了一种划分和计数油田地块的方法。根据给定的条件,通过遍历和DFS算法,将符合条件的地块标记为不符合条件的地块,并进行计数。同时,还介绍了如何判断点是否在给定范围内的方法。 ... [详细]
  • 本文介绍了解决二叉树层序创建问题的方法。通过使用队列结构体和二叉树结构体,实现了入队和出队操作,并提供了判断队列是否为空的函数。详细介绍了解决该问题的步骤和流程。 ... [详细]
  • 本文介绍了UVALive6575题目Odd and Even Zeroes的解法,使用了数位dp和找规律的方法。阶乘的定义和性质被介绍,并给出了一些例子。其中,部分阶乘的尾零个数为奇数,部分为偶数。 ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • 3.223.28周学习总结中的贪心作业收获及困惑
    本文是对3.223.28周学习总结中的贪心作业进行总结,作者在解题过程中参考了他人的代码,但前提是要先理解题目并有解题思路。作者分享了自己在贪心作业中的收获,同时提到了一道让他困惑的题目,即input details部分引发的疑惑。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
author-avatar
寒空动烟雪
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有