Codeforces 849D.Rooter's Song
2 seconds
256 megabytes
standard input
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.
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 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.
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
4 8
10 5
8 8
10 6
10 2
1 8
7 8
10 6
3 2 3
1 1 2
2 1 1
1 1 5
1 3
2 1
1 3
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的更多相关文章
- 【Codeforces】849D. Rooter's Song
[算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...
- codeforces 848B Rooter's Song 思维题
http://codeforces.com/problemset/problem/848/B 给定一个二维坐标系,点从横轴或纵轴垂直于发射的坐标轴射入(0,0)-(w,h)的矩形空间.给出点发射的坐标 ...
- Codeforces 848B Rooter's Song(分类+模拟)
题目链接 Rooter's Song 题意 有n个舞者站在x轴上或y轴上,每个人有不同的出发时间.x轴上的舞者垂直x轴正方向移动,y轴上的舞者垂直y轴正方向移动. 当x轴的舞者和y轴的舞者相遇时,他 ...
- codeforces 848B - Rooter's Song(构造+几何)
原题链接:http://codeforces.com/problemset/problem/848/B 题意:好多个人分别从x,y轴不同位置不同时间往垂直坐标轴方向移动,一旦相遇他们转向,问所有人的到 ...
- [CodeForces - 848B] Rooter's Song 思维 找规律
大致题意: 有一个W*H的长方形,有n个人,分别站在X轴或Y轴,并沿直线向对面走,第i个人在ti的时刻出发,如果第i个人与第j个人相撞了 那么则交换两个人的运动方向,直到走到长方形边界停止,问最后每个 ...
- codeforces 848B Rooter's Song
题目链接 正解:排序+模拟. 我们注意到两个点碰撞的必要条件,$pi+tj=pj+ti$,移项以后发现就是$pi-ti=pj-tj$,那么我们可以把$p-t$相同的点分为同一组. 然后我们还可以发现一 ...
- 【推导】【分类讨论】Codeforces Round #431 (Div. 1) B. Rooter's Song
给你一个这样的图,那些点是舞者,他们每个人会在原地待ti时间之后,以每秒1m的速度向前移动,到边界以后停止.只不过有时候会碰撞,碰撞之后的转向是这样哒: 让你输出每个人的停止位置坐标. ①将x轴上初始 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
随机推荐
- some方法过滤
// 已经存在该tab时跳过 this.tabs.some(item => item.title === option.title) || this.tabs.push(option)
- Android基础控件TextClock和Chronometer的使用
1.简介 DigitalClock, TextClock,AnalogClock,Chronometer其中DigitalClock和AnalogClock废弃了! TextClock是在Androi ...
- CAS(客户端)程序获取安全证书
以下是获取安全证书的一种方法,通过以下程序获取安全证书: import java.io.BufferedReader; import java.io.File; import java.io.File ...
- VC:不支持尝试执行的操作
问题描述: 基于CDialogEx的对话框工程.VS2010开发环境. 调试运行到OnInitDialog()的CDialogEx::OnInitDialog()方法的时候弹出提示窗口"不支 ...
- mysql三表联合查询,结果集合并
参考: mysql 结果集去重复值并合并成一行 SQL 三表联查 数据库三表连接查询怎么做 合并: MySQL中group_concat函数 完整的语法如下: group_concat([DISTIN ...
- Leetcode953. Verifying an Alien Dictionary验证外星语词典
某种外星语也使用英文小写字母,但可能顺序 order 不同.字母表的顺序(order)是一些小写字母的排列. 给定一组用外星语书写的单词 words,以及其字母表的顺序 order,只有当给定的单词在 ...
- Windows API 第19篇 FindFirstVolumeMountPoint FindNextVolumeMountPoint
相关函数:HANDLE FindFirstVolumeMountPoint( ...
- day26 作业
目录 TCP三次握手.四次挥手图 三次握手 四次挥手 简明理解三次握手 基于TCP开发一款远程CMD程序 TCP三次握手.四次挥手图 三次握手 第一次握手:客户端给服务端发一个 SYN 报文,并指明客 ...
- vue.js_03_vue.js的样式和修饰符
1.vue.js的样式 <body> <div id="app"> <h1 :style="styleObj1">这是一个h ...
- 【DM8168学习笔记4】ezsdk安装过程记录
安装文件 ezsdk_dm816x-evm_5_05_02_00_setuplinux DM8168-EZSDK文件结构如图所示. (图片来自:http://process ...