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

列方程组:两个人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. python使用twisted搭建的一个socket服务

    服务端 # -*- coding: utf-8 -*- # @Time : 2018/9/19 21:41 # @Author : cxa # @File : tsTservTW.py # @Soft ...

  2. c# List 所有操作方法例子

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Ref ...

  3. MongoDB安全:创建角色(User-Defined Roles)

    MongoDB已经定义了一些内建角色,同时还提供了用户自定义角色的功能,以满足用户千差万别的需求. 官文User-Defined Roles中对其有简略介绍,但要熟悉怎么创建角色,还需要了解下面的这些 ...

  4. 【Android开发日记】之入门篇(五)——Android四大组件之Service

    这几天忙着驾校考试,连电脑都碰不到了,今天总算告一段落了~~Service作为Android的服务组件,默默地在后台为整个程序服务,辅助应用与系统中的其他组件或系统服务进行沟通.它跟Activity的 ...

  5. 安装node版本管理工具之NVM

    nvm是个啥?nvm是一个可以让你在同一台机器上安装和切换不同版本node的工具. 你可能会问,为什么会有这个工具?有时候在开发的时候,对node版本有强制要求,有的要求用最新版本,有的要求用稳定版本 ...

  6. (一)问候 HtmlUnit

    第一节: HtmlUnit 简介 htmlunit 是一款开源的java 页面分析工具,读取页面后,可以有效的使用htmlunit分析页面上的内容.项目可以模拟浏览器运行,被誉为java浏览器的开源实 ...

  7. spark集群安装[转]

    [转]http://sofar.blog.51cto.com/353572/1352713 ====================================================== ...

  8. for循环输出菱形

    package com.hanqi; public class lingxing { public static void main(String[] args) { for(int m=1;m< ...

  9. abp zero 4.3 发布

    Demo URL: http://abpzerodemo.demo.aspnetzero.com Username: systemPassword: 123456 需要源码,请加QQ:3833-255 ...

  10. vue 笔记备份

    Vue实现数据双向绑定的原理:Object.defineProperty() vue实现数据双向绑定主要是:采用数据劫持结合发布者-订阅者模式的方式,通过Object.defineProperty() ...