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 ...
随机推荐
- 赛后总结——codeforces round 551 div2
传送门:QAQQAQ 好歹这次比赛打进前1000了...但第一题WA掉也是醉了... 每次比赛刚开始都是太心急,第一题写的特别快,不经过任何检查,结果最近两次比赛都死在了A题上... A题一上来把n, ...
- day72test
目录 models模型类 路由配置 视图配置 序列化组件配置 基于ModelSerializer类,完成Car资源的单查,群查,单增接口 序列化:显示车名,车的颜色,车的价格,车的海报,车的品牌 反序 ...
- ASP.NET MVC生命周期与管道模型
先来熟悉下asp.net请求管道 1.当客户端发送http://localhost:80/home/index请求时 2.首先到达服务端的内核模块HTTP.SYS(它监听80端口),通过访问注册表 ...
- scrapy中的ImagePipeline下载图片到本地、并提取本地的保存地址
通过scrapy内置到ImagePipeline下载图片到本地 在settings中打开 ITEM_PIPELINES的注释,并在这里面加入 'scrapy.pipelines.images.Imag ...
- springboot整合rabbitMQ时遇到的消息无法入列问题
问题描述: 对列和交换器配置如下(绑定的正常交换器的key是“convert”): 管理平台上手动发是可以的: 而通过程序发消息不行,根本没有进入队列: 解决:显式指定交换器(备选交换器和死信交换器都 ...
- 解决wordpress 5.3更新后Uncaught Typeerror: $ is not a function
本文不再更新,可能存在内容过时的情况,实时更新请移步原文地址:解决wordpress 5.3更新后Uncaught Typeerror: $ is not a function: 本文通过插件的办法解 ...
- P1009阶乘之和
n=int(input()) ans=0 for i in range(1,n+1): t=1 for j in range(1,i+1): t*=j; ans+=t; print(ans)
- cannot be cast to javax.servlet.Servlet 解决
使用maven创建web项目的时候,通过添加依赖的方式来添加servlet-api,如下 通过maven的命令(tomcat:run)来启动项目,发现访问的时候报错,错误如下: 错误排查: 首先查看s ...
- 移动端Web适配单位rem的坑,oppo r9手机出现错位bug
我们做了一个抽奖的H5活动页面,被一个oppo R9手机客户反馈,抽奖的转盘错位了.刷新了好几次都不行.网上百度一搜真的有部分安卓手机有坑.赶紧修复bug.分享完整的rem.js代码出来.各位看官自己 ...
- SQL Server中存储过程与函数的区别
本质上没区别.只是函数有如:只能返回一个变量的限制.而存储过程可以返回多个.而函数是可以嵌入在sql中使用的,可以在select中调用,而存储过程不行.执行的本质都一样. 函数限制比较多,比如不能用临 ...