Codeforces Round #431 (Div. 1) B. Rooter's Song(模拟)

题目链接:http://codeforces.com/contest/848/problem/B


很容易能看出来,相遇的情况只有在 y-t=x-t 的情况下才会成立,然后,按照x的坐标排序,从左向右模拟碰撞的情况即可,本代码用了一个循环队列模拟。


代码:

#include<bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
using namespace std;
const int MAXN=1e5+5;
const int ZERO=2e5+5000;
int n,w,h;
struct node
{
	int id,x,t;
	node(){}
	node(int _id,int _x,int _t):id(_id),x(_x),t(_t){}
	bool operator < (const node &a)const 
	{
		return x<a.x;
	}
}X[MAXN];
vector<node> Y[MAXN*4];
int cnt[MAXN*4];
pair<int,int> ans[MAXN];
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d%d",&n,&w,&h);
	int tot=0;
	for(int i=1;i<=n;i++)
	{
		int g,p,t;
		scanf("%d%d%d",&g,&p,&t);
		if(g==1)
		{
			X[++tot]=node(i,p,t);
		}
		else
		{
			Y[p-t+ZERO].push_back(node(i,p,t));
		}
	}
	sort(X+1,X+1+tot);
	for(int i=0;i<4*MAXN;i++)
	{
		sort(Y[i].begin(),Y[i].end());
	}
	for(int i=1;i<=tot;i++)
	{
		int pos=X[i].x-X[i].t+ZERO;
		int sz=Y[pos].size();
		if(sz)
		{
			int en=((sz-cnt[pos]-1)%sz+sz)%sz;
			swap(Y[pos][en].id,X[i].id);
			cnt[pos]++;
		}
		//printf("%d\n",X[i].id);
		ans[X[i].id]=mp(X[i].x,h);
	}
	for(int i=0;i<4*MAXN;i++)
	{
		int sz=Y[i].size();
		for(int j=0;j<sz;j++)
		{
			int pos=(((sz-cnt[i]-1)%sz+sz)%sz+j+1)%sz;
			ans[Y[i][pos].id]=mp(w,Y[i][j].x);
		}
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d %d\n",ans[i].xx,ans[i].yy);
	}
	return 0;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值