Welcoming autumn evening is the best for walking along the boulevard and npeople 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 fishe 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个人要走上一条路,这条路可以看成一条数轴,每个人用3个数据t,s,f描述,t表示上路的时间,s表示上路的起点,f表示走到的终点(起点可能大于终点,表示往左走),问这n个人每个人会与多少人相遇(走到同一点或互相穿过算相遇);

思路:
每个人的出发时间都不相同,不方便计算,那我们可以预处理一下,将所有点转化为出发时间相同。如果一个人是往左走(起点大于终点),那就将他的出发地点加上时间,向右走就将起点减去时间。这样,就可以将所有的点都看成是从0时刻出发的了。
预处理完之后,用一个for循环的嵌套进行两两遍历,没两个点之间就分两种情况:
1.两个点往相同的方向走:如果要能够相遇,就表示他们预处理完后的起点要相等,因为预处理完后,所有点出发时间都是0,如果起点不同,那两个点同时向一个方向移动,将永远不会相遇。、
而起点相同之后,还要判断两个点的行走区间是否有交集(这里的区间是指未初始化前的区间),有交集才表示会一同走到某一点后相遇。 2.两点的方向相反:若两点的方向相反,我们就可以求出他们相遇的点,就是两点预处理后的起点相加除以2,若求出的相遇的点在两个点行走的区间内,就表示能相遇。
这里的相遇还有一点比较特殊,那就是他们并不一定会走到同一点,比如两个点,一个在2位置,一个在3位置,下一秒,他们就互换了位置,而不会出现在同一点,这也算相遇。如果用整数(2+3)/2,将会得到2,结果可能会出错,所以我们可以用double型,得到一个小数,如果这个小数在两点的交集内,则是可行的。 代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#define eps 1e-7
#define ll long long
#define inf 0x3f3f3f3f
#define pi 3.141592653589793238462643383279
using namespace std;
int main()
{
double a[],b[],c[];
int n,visit[];
while(cin>>n)
{
memset(visit,,sizeof(visit));
for(int i=; i<n; ++i)
{
scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
if(b[i] > c[i]) //预处理使起始时间均为0
b[i] += a[i];
else
b[i] -= a[i];
} for(int i=; i<n-; ++i) //遍历每两个点是否相遇
{
for(int j=i+; j<n; ++j)
{
if(b[i] == b[j] && (b[i] > c[i] && b[j] > c[j] || b[i] < c[i] && b[j] < c[j]))
{ //若起点相同且往同一个方向走
if(b[i] < c[i] && b[j] < c[j]) //同时往右走
{
if( (b[i] + a[i] <= b[j]+a[j] && c[i] >= b[j]+a[j]) || (b[j] + a[j] <= b[i]+a[i] && c[j] >= b[i]+a[i]) )
{ //区间有交集
visit[i]++;
visit[j]++;
}
}
else if(b[i] > c[i] && b[j] > c[j]) //同时往左走
{
if( (b[i] - a[i] >= b[j] - a[j] && c[i] <= b[j] - a[j]) || (b[j] - a[j] >= b[i]-a[i] && c[j] <= b[i]-a[i]) )
{ //区间有交集
visit[i]++;
visit[j]++;
}
}
} else
{
double t = b[i] + b[j];
t /= ; //求出相遇的点
if(b[i] < c[i] && b[j] > c[j])
{
if(t >= b[i] + a[i] && t <= c[i] && t >= c[j] && t <= b[j] - a[j])
{ //交点在两区间内
visit[i]++;
visit[j]++;
}
}
else if(b[i] > c[i] && b[j] < c[j])
{
if(t <= b[i] - a[i] && t >= c[i] && t <= c[j] && t >= b[j] + a[j])
{ //交点在两区间内
visit[i]++;
visit[j]++;
}
}
}
}
}
for(int i=; i<n; ++i)
printf("%d%c",visit[i],i == n- ? '\n':' ');
}
return ;
}
/*
2
1 2 3
2 2 1
*/
 

CodeForces - 589D —(思维题)的更多相关文章

  1. Codeforces 424A (思维题)

    Squats Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Statu ...

  2. Vova and Trophies CodeForces - 1082B(思维题)

    Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...

  3. CodeForces - 417B (思维题)

    Crash Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

  4. CodeForces - 417A(思维题)

    Elimination Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit  ...

  5. B - Sonya and Exhibition CodeForces - 1004B (思维题)

    B. Sonya and Exhibition time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  7. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  8. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  10. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

随机推荐

  1. 黄聪:C#程序中判断是否处在DEBUG调试状态或者RELEASE发布状态

    习惯了用老方式(注释的方式)来对程序进行调试,不过昨天才发现这样调试存在很大的隐患:在工程发布的时候如果忘记把该注释的代码注释掉,而让这些调试信息随工程一起发布,如果是可见的调试信息倒好发现,如果不是 ...

  2. [DP题]采药

    1775:采药 总时间限制:1000ms内存限制:65536kB 描述 辰辰是个很有潜能.天资聪颖的孩子,他的梦想是称为世界上最伟大的医师.为此,他想拜附近最有威望的医师为师.医师为了判断他的资质,给 ...

  3. 转转转---js正则表达exec与match的区别说明

    正则表达式对象有两个定义方式:: 1.第一种定义: new RegExp(pattern, attributes);如var reg = new RegExp("abc",&quo ...

  4. postman全方位讲解(有空看下)

    Postman 接口测试神器 Postman 是一个接口测试和 http 请求的神器,非常好用. 官方 github 地址: https://github.com/postmanlabs Postma ...

  5. [win10]遇坑指南

    好多不好用的地方,现在解决的差不多了,把经验分享一下,也方便自己下一次重装 win10 时不再进坑. 1. 输入法:https://zhidao.baidu.com/question/45942172 ...

  6. 折腾一天,获取下列多选框的所有选中值,原生js可直接通过obj.val()来获取,可jq不行,要通过循环取值来获取;

    折腾一天,获取下列多选框的所有选中值,原生js可直接通过obj.val()来获取,可jq不行,要通过循环取值来获取;

  7. aix操作系统的版本中TL SP 含义

    AIX 分为四个主要的操作系统级别:版本.发行版.技术级 (TL) 和服务包 (SP).版本和发行版通常指的是 AIX 的名称,例如AIX 7.1.TL 是包含重大更新的操作系统的发行版,而 SP 包 ...

  8. oracle中bulk collect into用法

    通过bulk collect减少loop处理的开销 采用bulk collect可以将查询结果一次性地加载到collections中. 而不是通过cursor一条一条地处理. 可以在select in ...

  9. IBM X3650 M4 主板故障

    故障描述: 今天突然接到报警,一台服务器无法连通,无法登录.无法 ping 通. 打电话到 IDC ,授权工程师查看服务器状态,返回结果如下: 1.服务器关机状态 2.无法开机 ( 电源灯亮 ),按开 ...

  10. lda spark 代码官方文档

    http://spark.apache.org/docs/1.6.1/mllib-clustering.html#latent-dirichlet-allocation-lda http://spar ...