• CodeForces


    题目链接:http://codeforces.com/problemset/problem/589/D

    Welcoming autumn evening is the best for walking along the boulevard and n people decided to do so.

    The boulevard can be represented as the axis Ox. For every person there are three parameters characterizing the behavior: ti, si, fi — the moment of time when the i-th person starts walking, the start point and the end point of the walk respectively. Each person moves in a straight line along the boulevard from si to fi with a constant speed of either 1 or  - 1 depending on the direction.

    When the i-th person appears on the boulevard at the point si she immediately starts walking towards the point fi.

    If two or more persons meet at the boulevard (they are at the same point at the same time, no matter which directions they are going) they all greet each other. Like in the normal life, every pair of people greet each other at most once.

    You task is to calculate for every person how many people she greets while walking along the boulevard.

    Please, pay attention to the fact that i-th person may meet and greet any other person at points si and fi. After a person achieves the destination point fi she moves out of the boulevard and cannot greet anyone else. The same rule applies to the start of the walk: a person cannot greet anyone until she appears on the boulevard.

    Input

    In the first line there is an integer n (2 ≤ n ≤ 1000) — the number of people who decided to go for a walk.

    The following n lines contain parameters for n people. In the i-th line there are three positive integers ti, si, fi (1 ≤ ti, si, fi ≤ 106,  si ≠ fi), where ti, si, fi — the moment of time when the i-th person starts walking, the start point and the end point of the walk respectively.

    Output

    The single line of the output should contain a sequence of n integers r1, r2, ..., rn separated by a space, where ri denotes the number which the i-th person greets other people while walking along the boulevard.

    Examples
    Input
    3
    1 1 10
    5 8 2
    9 9 10
    Output
    2 1 1 
    Input
    3
    3 2 4
    4 3 4
    3 6 4
    Output
    2 2 2 
    题目大意:输入n,代表有n个人,接下来n行代表每个人的开始时间,出发点,终点,速度都为1或者-1,按照出发点和终点位置判断,两个人见面时要打招呼,前提是一定要开始走动,走完或者没有走都不能打招呼
    叫你求每个人要打多少次招呼
    个人思路:比赛的时候没时间做这道题,刚刚补题,没想到直接ac,不过这道题挺简单的,思路都在代码中
    #include<iostream>
    #include<string.h>
    #include<map>
    #include<cstdio>
    #include<cstring>
    #include<stdio.h>
    #include<cmath>
    #include<math.h>
    #include<algorithm>
    #include<set>
    #include<queue>
    typedef long long ll;
    using namespace std;
    const ll mod=1e9+7;
    const int maxn=1e3+10;
    const int maxk=100+10;
    const int maxx=1e4+10;
    const ll maxe=1000+10;
    #define INF 0x3f3f3f3f3f3f
    #define Lson l,mid,rt<<1
    #define Rson mid+1,r,rt<<1|1
    struct P
    {
        int time,be,en,sum,di;//分别是开始时间,开始位置,结束位置,打招呼次数,方向
    }p[maxn];
    int n;
    void solve(int i,int j)
    {
        int b1,b2;
        if(p[i].time<=p[j].time)//第一种情况
        {
            b1=p[i].be+p[i].di*(p[j].time-p[i].time);//先把初始时间变为一样,先走的先走,后走的不变
            if((b1>=p[i].be&&b1<=p[i].en)||(b1>=p[i].en&&b1<=p[i].be))//变化之后还在该点范围内
            {
                int mi=min(abs(p[i].en-b1),abs(p[j].en-p[j].be));//取到达终点时间少的,因为一个到达了就不会再打招呼了
                if(b1<=p[j].be&&(b1+mi*p[i].di>=p[j].be+mi*p[j].di))//第一个刚开始的位置小于第二个刚开始的位置,变化之后大于了,那么证明肯定有见面的时候
                {
                    p[i].sum++;
                    p[j].sum++;
                }
                else if(b1>=p[j].be&&(b1+mi*p[i].di<=p[j].be+mi*p[j].di))//刚开始的位置大于第二个的位置,变化之后小于第二个的位置,证明肯定有见面的时候
                {
                    p[i].sum++;
                    p[j].sum++;
                }
            }
            else//不在范围内,证明第二个点还没有出发就已经到达终点了
                return ;
        }
        else//以下同理
        {
            b2=p[j].be+p[j].di*(p[i].time-p[j].time);
            if((b2>=p[j].be&&b2<=p[j].en)||(b2>=p[j].en&&b2<=p[j].be))
            {
                int mi=min(abs(p[i].en-p[i].be),abs(p[j].en-b2));
                if(b2<=p[i].be&&(b2+mi*p[j].di>=p[i].be+mi*p[i].di))
                {
                    p[i].sum++;
                    p[j].sum++;
                }
                else if(b2>=p[i].be&&(b2+mi*p[j].di<=p[i].be+mi*p[i].di))
                {
                    p[i].sum++;
                    p[j].sum++;
                }
            }
            else
                return ;
        }
    }
    int main()
    {
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>p[i].time>>p[i].be>>p[i].en;
            p[i].sum=0;
            if(p[i].be<=p[i].en) p[i].di=1;
            else  p[i].di=-1;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                solve(i,j);
            }
        }
        for(int i=0;i<n;i++)
            cout<<p[i].sum<<" ";
        cout<<endl;
        return 0;
    }
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    百度mp3地址解密码
    VB 在EXE后附加信息
    截屏函数
    Base64和StrToByte
    The Android ION memory allocator, DMABUF is mentioned as well
    DDC EDID 介绍
    Memory management for graphic processors TTM的由来
    科普 写display driver的必看 How video card works [2D的四种主要操作]
    GEM vs TTM
    DMABUF 背景介绍文章 Sharing buffers between devices
  • 原文地址:https://www.cnblogs.com/caijiaming/p/9408235.html
Copyright © 2020-2023  润新知