CodeForces - 555C Case of Chocolate set pair

题目链接:点击查看

题意:有一个n*n的矩形,给你对角线上的坐标,给你一个方向,问能走几个坐标,遇到之前已经经过的坐标就停止

题解:当给你一个坐标(x,y),方向向上时,他能所经过的点数是受y比他大的那些点影响的,并且比y大离y最近的那个点向上能到达哪个x值,他就能到达哪个x值,如果之前有点(x1,y1)向左,那也就说明这个点没法向上了,这个点的向上临界值就为x。向左的同理是受大于x的那些点影响的。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

set< pair<int,int> > s1, s2;
map< pair<int,int>, int> mp;
int n, q;
int main()
{
	pair<int,int > pos;
	int x, y;
	
	char op[2];
	scanf("%d %d", &n, &q);
	s1.insert(make_pair(n+1, 0) ); // 设置基准
	s2.insert(make_pair(n+1, 0) );
	while(q--) {
		scanf("%d %d %s", &y, &x, op);
		if(mp[ make_pair(x,y) ] ) 
		{
			printf("0\n");
			continue;
		}
		mp[ make_pair(x,y) ] = 1;
		if(op[0] == 'U') {
			pos = *s1.lower_bound( make_pair(y, 0) );
			printf("%d\n", x - pos.second);
			
			s1.insert( make_pair(y, pos.second) );
			
			s2.insert( make_pair(x, y) );
		} else {
			pos = *s2.lower_bound( make_pair(x, 0) );
		//	cout<<pos.first<<" "<<pos.second<<endl;
			printf("%d\n", y - pos.second);
			
			s2.insert( make_pair(x, pos.second) );
			s1.insert( make_pair(y, x));
		}
	}
	
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值