• Codeforces Round #431 (Div. 2) D. Rooter's Song


    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相等的若干点进行分析。

    将从y轴上出发的点坐标按从大到小排列,从x轴出发的按从小到大排列。

    分析每一条线上发生的交换过程即可找到对应的终点属于哪一个点。对于x轴出发坐标离原点最近的这条射线,与y轴出发的点依次交换(按y坐标从小到大)故最终属于y最大的点。考虑下一条从x轴点出发的线,y轴出发原本坐标最大的点已经有了配属,而其余的点仍在继续向右(因为先前发生两次交换,方向不变)只需要找当下y坐标最大的……依次类推,根据对称性,y轴上点出发的线是同理的,依照这种分配方式即可找到最终的答案。

      1 #include <cstdio>
      2 #include <iostream>
      3 #include <algorithm>
      4 #include <vector>
      5 #include <set>
      6 #include <map>
      7 #include <string>
      8 #include <cstring>
      9 #include <stack>
     10 #include <queue>
     11 #include <cmath>
     12 #include <ctime>
     13 #include<bitset>
     14 #include <utility>
     15 using namespace std;
     16 #define rank rankk
     17 #define mp make_pair
     18 #define pb push_back
     19 #define xo(a,b) ((b)&1?(a):0)
     20 //#define LL ll
     21 typedef unsigned long long ull;
     22 typedef pair<int,int> pii;
     23 typedef long long ll;
     24 typedef pair<ll,int> pli;
     25 const int INF=0x3f3f3f3f;
     26 const ll INFF=0x3f3f3f3f3f3f3f3fll;
     27 const int MAX=1e5+5;
     28 const int MAX_N=MAX;
     29 const ll MOD=998244353;
     30 const long double pi=acos(-1.0);
     31 //const double eps=0.00000001;
     32 int gcd(int a,int b){return b?gcd(b,a%b):a;}
     33 template<typename T>inline T abs(T a) {return a>0?a:-a;}
     34 template<class T> inline
     35 void read(T& num) {
     36     bool start=false,neg=false;
     37     char c;
     38     num=0;
     39     while((c=getchar())!=EOF) {
     40         if(c=='-') start=neg=true;
     41         else if(c>='0' && c<='9') {
     42             start=true;
     43             num=num*10+c-'0';
     44         } else if(start) break;
     45     }
     46     if(neg) num=-num;
     47 }
     48 inline ll powMM(ll a,ll b,ll M){
     49     ll ret=1;
     50     a%=M;
     51 //    b%=M;
     52     while (b){
     53         if (b&1) ret=ret*a%M;
     54         b>>=1;
     55         a=a*a%M;
     56     }
     57     return ret;
     58 }
     59 void open()
     60 {
     61     freopen("1009.in","r",stdin);
     62     freopen("out.txt","w",stdout);
     63 }
     64 int n,w,h;
     65 int anx[MAX],any[MAX];
     66 vector<int>temx,temy;
     67 struct node
     68 {
     69     int pos,t,id,kind,he;
     70     bool operator <(const node& x)const
     71     {
     72         if(he!=x.he)return he<x.he;
     73         if(kind!=x.kind)return kind>x.kind;
     74         if(kind==1)return pos<x.pos;
     75         else return pos>x.pos;
     76     }
     77 }a[MAX];
     78 int main()
     79 {
     80     scanf("%d%d%d",&n,&w,&h);
     81     for(int i=1;i<=n;i++)
     82     {
     83         scanf("%d%d%d",&a[i].kind,&a[i].pos,&a[i].t);a[i].id=i;a[i].he=a[i].pos-a[i].t;
     84     }
     85     sort(a+1,a+1+n);
     86     for(int i=1;i<=n;)
     87     {
     88         int j,cnt=0;
     89         for(j=i;j<=n&&a[j].he==a[i].he;j++)
     90         {
     91             if(a[j].kind==1)
     92                 temx.push_back(a[j].pos);
     93             else
     94                 temy.push_back(a[j].pos);
     95         }
     96         for(int s=i;s<j;s++,++cnt)
     97             if(cnt<temx.size())anx[a[s].id]=temx[cnt],any[a[s].id]=h;
     98             else anx[a[s].id]=w,any[a[s].id]=temy[cnt-temx.size()];
     99         i=j;vector<int>().swap(temx);vector<int>().swap(temy);
    100     }
    101     for(int i=1;i<=n;i++)
    102         printf("%d %d
    ",anx[i],any[i]);
    103     return 0;
    104 }
  • 相关阅读:
    2021.11.20 MapReduce实验
    Linux串口应用编程
    Linux系统中的TTY
    69 进程创建的优化设计 上
    71 键盘驱动程序设计(上)
    有关EXPORT_SYMBOL_GPL
    73 键盘驱动程序设计(下)
    72 键盘驱动程序设计(中)
    本地maven打包无法被导入
    java 8 Stream 递归实现树形结构
  • 原文地址:https://www.cnblogs.com/quintessence/p/7465765.html
Copyright © 2020-2023  润新知