题意:给你一条直线以及初始时刻这条直线上的一些人的坐标,以及他们的速度矢量。让你对每个人计算他在过去无限远到将来无限远的时间内会与多少人处于同一个点,然后对每个人的这个值求和。

列方程组:两个人i,j相撞的条件是:

a*x(i)+b+t*vy(i)=a*xj+b+t*vy(j)

x(i)+t*vx(i)=xj+t*vx(j)

化简得vy(i)-a*vx(i)=vy(j)-a*vx(j),对这个值排序,就能统计了。别忘了减去vx相等的点对贡献的答案(这种情况画个图出来,显然永远不会相撞)。

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
ll a,b;
typedef pair<ll,ll> Point;
Point c[200005];
int main(){
ll x,va,vb;
scanf("%d%I64d%I64d",&n,&a,&b);
for(int i=1;i<=n;++i){
scanf("%I64d%I64d%I64d",&x,&va,&vb);
c[i].first=vb-a*va;
c[i].second=va;
}
sort(c+1,c+n+1);
ll ans=0;
int sta;
for(int i=1;i<=n;++i){
if(i==1 || c[i].first!=c[i-1].first){
sta=i;
}
if(i==n || c[i].first!=c[i+1].first){
ans+=(ll)(i-sta+1)*(ll)(i-sta);
}
}
for(int i=1;i<=n;++i){
if(i==1 || (c[i].first!=c[i-1].first || c[i].second!=c[i-1].second)){
sta=i;
}
if(i==n || (c[i].first!=c[i+1].first || c[i].second!=c[i+1].second)){
ans-=(ll)(i-sta+1)*(ll)(i-sta);
}
}
printf("%I64d\n",ans);
return 0;
}

【推导】Codeforces Round #478 (Div. 2) D. Ghosts的更多相关文章

  1. 【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D

    传送门 题意:给你一条直线的斜率a和截距b,和某一时刻n个在直线上的点的横坐标,以及沿坐标轴方向的速度.问你这些点在(-∞,+∞)的时间内的碰撞次数. solution 设两个点在t时刻相碰,有: x ...

  2. Codeforces Round #478 (Div. 2)

    题目链接:http://codeforces.com/contest/975 A. Aramic script time limit per test:1 second memory limit pe ...

  3. Codeforces Round #478 (Div. 2) ABCDE

    A. Aramic script time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. B. Mancala (Codeforces Round #478 (Div. 2))

    #include <bits/stdc++.h> using namespace std; ; typedef long long ll; ll a[maxn]; ll b[maxn]; ...

  5. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  6. CodeForces 840C - On the Bench | Codeforces Round #429 (Div. 1)

    思路来自FXXL中的某个链接 /* CodeForces 840C - On the Bench [ DP ] | Codeforces Round #429 (Div. 1) 题意: 给出一个数组, ...

  7. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  8. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  9. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

随机推荐

  1. Access中替代case when的方法 .

    最近在做一个用Access的东东,其中用到了case when的方式,但是Access是不支持这种语法的,查询知道IIf和Swith可以作为替代,总结如下: IIf(expr, truepart, f ...

  2. linux下/var/run目录下.pid文件的作用

    1.pid文件的内容用cat命令查看,可以看到内容只有一行,记录了该进程的ID 2.pid文件的作用防止启动多个进程副本 3.pid文件的原理进程运行后会给.pid文件加一个文件锁,只有获得该锁的进程 ...

  3. python网络编程--进程池

    一:进程池 进程池内部维护一个进程序列,当使用时,则去进程池中获取一个进程, 如果进程池序列中没有可供使用的进进程,那么程序就会等待,直到进程池中有可用进程为止. 进程池中有两个方法: apply a ...

  4. C# listView subitem 问本值 text 改变 界面会闪烁

    解决方法 就是重写ListView,然后设置双缓冲即可,然后再使用DoubleBufferListView,就不会闪烁了.下面的代码是DoubleBufferListView,并使用FrmMain来测 ...

  5. MICROSOFT SQLSERVER 总结

    --语 句 功 能--数据操作Select --从数据库表中检索数据行和列Insert --向数据库表添加新数据行Delete --从数据库表中删除数据行Update --更新数据库表中的数据--数据 ...

  6. IntelliJ IDEA 显示行号

    设置方法如下:   File->Settings->Editor->Appearence->Show Line Number

  7. 微商城三级分销源码公众号开发 微分销 C#源码

    需要源码,请加QQ:858-048-581 ,可以查看演示 运行环境:vs2012+ sql2008r2 [什么是微分销] 微分销是助力企业进军移动电商,完善分销体系搭建微信分销系统.基于微信平台,搭 ...

  8. bzoj 3926 转换+广义后缀自动机

    思路:重点在于叶子节点只有20个,我们把叶子节点提到根,把20个trie图插入后缀自动机,然后就是算有多少个本质不同的字串. #include<bits/stdc++.h> #define ...

  9. C语言可变参数个数

    #include <stdio.h>#include <stdarg.h> void test(const char * format, ...); int main(void ...

  10. redis配置新端口

    为redis分配一个8888端口,操作步骤如下:1.$REDIS_HOME/redis.conf重新复制一份,重命名为redis8888.conf.2.打开redis8888.conf配置文件,找到p ...