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

列方程组:两个人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. sru源码--language model

    import sys import os import argparse import time import random import math import numpy as np import ...

  2. JDK1.8源码ArrayList

    线程不安全的,如果要想线程安全必须在创建的时候就采用线程安全的方式创建: List list = Collections.synchronizedList(new ArrayList(...)); 引 ...

  3. Tslib步骤以及出现问题的解决方案【转】

    转自:http://forum.eepw.com.cn/thread/267828/1 嵌入式设备中触摸屏使用非常广泛,但触摸屏的坐标和屏的坐标是不对称的,需要校准.校准广泛使用的是开源的tslib. ...

  4. 对于Linux平台下C语言开发中__sync_函数的认识(转)

    reference:http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html#Atomic-Builtins A built-i ...

  5. Python爬取微信好友

    前言 今天看到一篇好玩的文章,可以实现微信的内容爬取和聊天机器人的制作,所以尝试着实现一遍,本文记录了实现过程和一些探索的内容 来源: 痴海 链接: https://mp.weixin.qq.com/ ...

  6. MySQL字符集编码相关

    Windows 10家庭中文版,MySQL  5.7.20,2018-05-07 Part.1 查找数据库的字符集编码 查看MySQL字符集编码:status命令 使用命令行登录MySQL服务器,然后 ...

  7. windows下redis服务操作

    安装redis服务redis-server --service-install redis.windows.conf --service-name Redis26380 --loglevel verb ...

  8. MST最小生成树

    首先,贴上一个很好的讲解贴: http://www.wutianqi.com/?p=3012 HDOJ 1233 还是畅通工程 http://acm.hdu.edu.cn/showproblem.ph ...

  9. Spark介绍及安装部署

    一.Spark介绍 1.1 Apache Spark Apache Spark是一个围绕速度.易用性和复杂分析构建的大数据处理框架(没有数据存储).最初在2009年由加州大学伯克利分校的AMPLab开 ...

  10. 实时流计算、Spark Streaming、Kafka、Redis、Exactly-once、实时去重

    http://lxw1234.com/archives/2018/02/901.htm