D. Rooter's Song
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Wherever the destination is, whoever we meet, let's render this song together.

On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage.

On the sides of the stage stand n dancers. The i-th of them falls into one of the following groups:

  • Vertical: stands at (xi, 0), moves in positive y direction (upwards);
  • Horizontal: stands at (0, yi), moves in positive x direction (rightwards).

According to choreography, the i-th dancer should stand still for the first ti milliseconds, and then start moving in the specified direction at 1 unit per millisecond, until another border is reached. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.

When two dancers collide (i.e. are on the same point at some time when both of them are moving), they immediately exchange their moving directions and go on.

Dancers stop when a border of the stage is reached. Find out every dancer's stopping position.

Input

The first line of input contains three space-separated positive integers n, w and h (1 ≤ n ≤ 100 000, 2 ≤ w, h ≤ 100 000) — the number of dancers and the width and height of the stage, respectively.

The following n lines each describes a dancer: the i-th among them contains three space-separated integers gi, pi, and ti (1 ≤ gi ≤ 2, 1 ≤ pi ≤ 99 999, 0 ≤ ti ≤ 100 000), describing a dancer's group gi (gi = 1 — vertical, gi = 2 — horizontal), position, and waiting time. If gi = 1 then pi = xi; otherwise pi = yi. It's guaranteed that 1 ≤ xi ≤ w - 1 and 1 ≤ yi ≤ h - 1. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.

Output

Output n lines, the i-th of which contains two space-separated integers (xi, yi) — the stopping position of the i-th dancer in the input.

Examples
Input
8 10 8
1 1 10
1 4 13
1 7 1
1 8 2
2 2 0
2 5 14
2 6 0
2 6 1
Output
4 8
10 5
8 8
10 6
10 2
1 8
7 8
10 6
Input
3 2 3
1 1 2
2 1 1
1 1 5
Output
1 3
2 1
1 3
Note

The first example corresponds to the initial setup in the legend, and the tracks of dancers are marked with different colours in the following figure.

In the second example, no dancers collide.

【题解】

不(题)难(解)发(上)现(说)两个点能够相碰当且仅当p - t相等

于是我们可以按照p - t分组,发现两个点相碰可以看做穿过去。那么

最终位置与原始位置有什么对应关系呢?

我们把每个点的路径化成直线,交点意味着碰撞。我们发现一个点的行走轨迹是

阶梯状的,手画一下不难发现:左上->左下->右下方向的点对应左上->右上->

右下的点

于是两次间接排序即可

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b)) const int INF = 0x3f3f3f3f;
const int MAXN = + ; inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
} inline int abs(int a)
{
return a < ? -*a : a;
} struct Node
{
int g, p, t, x, y;
}node[MAXN],ans[MAXN]; int n,w,h,cnt[MAXN],cnt2[MAXN]; int cmp(int c, int d)
{
Node a = node[c], b = node[d];
return (a.p - a.t == b.p - b.t) ? ( (a.y == b.y) ? (a.x > b.x) : (a.y < b.y)) : (a.p - a.t < b.p - b.t);
} int cmp2(int c, int d)
{
Node a = node[c], b = node[d];
return (a.p - a.t == b.p - b.t) ? ((a.x == b.x) ? (a.y < b.y) : (a.x > b.x)) : (a.p - a.t < b.p - b.t);
} int main()
{
read(n), read(w), read(h);
for(register int i = ;i <= n;++ i)
{
read(node[i].g), read(node[i].p), read(node[i].t);
if(node[i].g == ) node[i].y = -, node[i].x = node[i].p;
else node[i].y = node[i].p, node[i].x = -;
cnt[i] = cnt2[i] = i;
}
std::sort(cnt + , cnt + + n, cmp);
for(register int i = ;i <= n;++ i)
if(node[i].x != -)node[i].y = h;
else node[i].x = w;
std::sort(cnt2 + , cnt2 + + n, cmp2);
for(register int i = ;i <= n;++ i)
ans[cnt[i]] = node[cnt2[i]];
for(register int i = ;i <= n;++ i)
printf("%d %d\n", ans[i].x, ans[i].y);
return ;
}

849D

Codeforces 849D.Rooter's Song的更多相关文章

  1. 【Codeforces】849D. Rooter's Song

    [算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...

  2. codeforces 848B Rooter's Song 思维题

    http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标 ...

  3. Codeforces 848B Rooter's Song(分类+模拟)

    题目链接 Rooter's Song 题意  有n个舞者站在x轴上或y轴上,每个人有不同的出发时间.x轴上的舞者垂直x轴正方向移动,y轴上的舞者垂直y轴正方向移动. 当x轴的舞者和y轴的舞者相遇时,他 ...

  4. codeforces 848B - Rooter's Song(构造+几何)

    原题链接:http://codeforces.com/problemset/problem/848/B 题意:好多个人分别从x,y轴不同位置不同时间往垂直坐标轴方向移动,一旦相遇他们转向,问所有人的到 ...

  5. [CodeForces - 848B] Rooter's Song 思维 找规律

    大致题意: 有一个W*H的长方形,有n个人,分别站在X轴或Y轴,并沿直线向对面走,第i个人在ti的时刻出发,如果第i个人与第j个人相撞了 那么则交换两个人的运动方向,直到走到长方形边界停止,问最后每个 ...

  6. codeforces 848B Rooter's Song

    题目链接 正解:排序+模拟. 我们注意到两个点碰撞的必要条件,$pi+tj=pj+ti$,移项以后发现就是$pi-ti=pj-tj$,那么我们可以把$p-t$相同的点分为同一组. 然后我们还可以发现一 ...

  7. 【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song

    给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止.只不过有时候会碰撞,碰撞之后的转向是这样哒: 让你输出每个人的停止位置坐标. ①将x轴上初始 ...

  8. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  9. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

随机推荐

  1. ios与android设备即时语音互通的录音格式预研说明

    本文虽属原创,但是内容都是来自于网络,参考了大家的微博,以及论坛的总结. 在做语音对讲的时候,将会碰到录制语音格式的问题,因为要考虑自己开发设备的支持的格式,还要考虑其他设备操作系统的支持的格式,以及 ...

  2. 按钮事件v-on

    <!DOCTYPE html> <html lang="zh"> <head> <title></title> < ...

  3. Data too long for column

    一篇文章的正文,需要很多字数,默认就是255,不够 @Lob @Basic @Type(type = "text") @Column(name = "detail&quo ...

  4. Delphi XE10百集视频教程计划

    1. 前言 本人现在的职业是Java程序员,一直想学习一个做桌面应用的编程语言,几年前无意中接触到Delphi,比VB功能强大,比C++语法更容易理解,加上Oracle的PL/SQL的底子,最终决定学 ...

  5. 《DSP using MATLAB》Problem 8.26

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  6. 恭喜"微微软"喜当爹,Github嫁入豪门。

    今天是 Github 嫁入豪门的第 2 天,炒得沸沸扬扬的微软 Github 收购事件于昨天(06月04日)尘埃落定,微软最终以 75 亿美元正式收购 Github. 随后,Gitlab 趁势带了一波 ...

  7. 让ASPX页面可以提交html标签代码的配置

    1:打开web.config文件,在system.web节点里,添加<httpRuntime requestValidationMode="2.0" /> 2:在asp ...

  8. css3之字体@font-face

    @font-face能够加载服务器端的字体文件,让浏览器端可以显示用户电脑里没有安装的字体. 浏览器支持 表格中的数字表示支持该属性的第一个浏览器版本号. Firefox, Chrome, Safar ...

  9. 第一次个人项目【词频统计】——测试样例分析&性能分析

    [空文件测试](认为空文件行数为0) [基本测试] [大小写测试] 可以看出abcd同类型的词出现了三次,而单词树中存储的是ABCd,满足大小写要求. [复杂文件测试] 前三项数据比较接近,但是单词和 ...

  10. 谈一谈创建React Component的几种方式

    当我们谈起React的时候,多半会将注意力集中在组件之上,思考如何将页面划分成一个个组件,以及如何编写可复用的组件.但对于接触React不久,还没有真正用它做一个完整项目的人来说,理解如何创建一个组件 ...