题目链接: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
31 1 105 8 29 9 10

Output
2 1 1 

Input
33 2 44 3 43 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++;}}elsereturn ;}
}
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;
}

转载于:https://www.cnblogs.com/caijiaming/p/9408235.html

CodeForces - 589D相关推荐

  1. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

  2. 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

    题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...

  3. 【codeforces 812C】Sagheer and Nubian Market

    [题目链接]:http://codeforces.com/contest/812/problem/C [题意] 给你n个物品; 你可以选购k个物品;则 每个物品有一个基础价值; 然后还有一个附加价值; ...

  4. CodeForces 获得数据

    针对程序的输出可以看见 CodeForces :当输入.输出超过一定字符,会隐藏内容 所以:分若干个程序进行输入数据的获取 1. 1 for (i=1;i<=q;i++) 2 { 3 scanf ...

  5. codeforces水题100道 第二十七题 Codeforces Round #172 (Div. 2) A. Word Capitalization (strings)...

    题目链接:http://www.codeforces.com/problemset/problem/281/A 题意:将一个英文字母的首字母变成大写,然后输出. C++代码: #include < ...

  6. CodeForces 595A

    题目链接: http://codeforces.com/problemset/problem/595/A 题意: 一栋楼,有n层,每层有m户,每户有2个窗户,问这栋楼还有多少户没有睡觉(只要一个窗户灯 ...

  7. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  8. Codeforces Round #506 (Div. 3)

    Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...

  9. Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈)

    Codeforces Round #417:E. FountainsSagheer and Apple Tree(树上博弈) 标签: codeforces 2017-06-02 11:41 29人阅读 ...

最新文章

  1. FASTQ! BAM! VCF
  2. 团队冲刺第二阶段-2
  3. Beta版冲刺Day1
  4. linux java ocr_Linux环境如何支持使用tess4j进行ORC
  5. 一图揭示:营销的目的、策略、战略
  6. 子页面刷新父页面,避免弹出重复提交窗口
  7. 华为手机可以下载鸿蒙系统吗_华为鸿蒙手机系统首次曝光,汉字界面简洁明了...
  8. imx6 i2c分析
  9. 声压级和灵敏度的关系
  10. php wps导入数据库,金山的wps的表格怎样导入sqlserver2008数据库中??_wps excel表格怎么导入数据库...
  11. 临近秋招实习,科普一下“内推”的利优势
  12. 高级项目经理的企业需求、企业地位
  13. oracle 压缩备份比率,Oracle 10g备份集压缩(Backupset Compression)
  14. java计算机毕业设计基于安卓Android/微信小程序的婚恋交友系统uni-app
  15. 这些数据爬虫网站,帮你工作提质增效,还不收藏?
  16. java程序设计 c语言_C语言和Java编程有什么区别?
  17. ajax 分页 php,phpajax分页一_PHP教程
  18. Flutter 自定义Dialog
  19. ALSA: Adversarial Learning of Supervised Attentions for VQA (VQA中有监督注意的对抗学习)
  20. java的内容好复杂_Java I/O 好复杂,傻傻分不清楚,别担心,我们有线索了……...

热门文章

  1. iisweb服务器完美解决方案
  2. 解决gitlab关闭登录选项问题
  3. plsql连接本地oracle数据库,而远程主机却无法连接,出现无监听程序的解决方法(转)
  4. idea actiBPM插件生成png文件 (解决没有Diagrams或Designer选项问题)
  5. 【报告分享】2020直播电商分析报告-抖音VS快手.pdf(附下载链接)
  6. 字符串算法-Rabin-Karp
  7. 【优秀选手采访】看十强选手如何顺利拿下腾讯offer
  8. android 广播反注册后,BroadcastReceiver注册、使用及其权限
  9. pytorch:tensor的运算
  10. 关于稀疏矩阵转化为稠密矩阵问题 (scipy.sparse格式和tensor稀疏张量格式)