【推导】Codeforces Round #478 (Div. 2) D. Ghosts
题意:给你一条直线以及初始时刻这条直线上的一些人的坐标,以及他们的速度矢量。让你对每个人计算他在过去无限远到将来无限远的时间内会与多少人处于同一个点,然后对每个人的这个值求和。
列方程组:两个人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的更多相关文章
- 【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D
传送门 题意:给你一条直线的斜率a和截距b,和某一时刻n个在直线上的点的横坐标,以及沿坐标轴方向的速度.问你这些点在(-∞,+∞)的时间内的碰撞次数. solution 设两个点在t时刻相碰,有: x ...
- Codeforces Round #478 (Div. 2)
题目链接:http://codeforces.com/contest/975 A. Aramic script time limit per test:1 second memory limit pe ...
- Codeforces Round #478 (Div. 2) ABCDE
A. Aramic script time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- B. Mancala (Codeforces Round #478 (Div. 2))
#include <bits/stdc++.h> using namespace std; ; typedef long long ll; ll a[maxn]; ll b[maxn]; ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- CodeForces 840C - On the Bench | Codeforces Round #429 (Div. 1)
思路来自FXXL中的某个链接 /* CodeForces 840C - On the Bench [ DP ] | Codeforces Round #429 (Div. 1) 题意: 给出一个数组, ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- Computer Vision Resources
Computer Vision Resources Softwares Topic Resources References Feature Extraction SIFT [1] [Demo pro ...
- MUI项目基础框架
码云SVN仓库地址:https://gitee.com/lim2018/vx/tree/master MUI项目基础框架,底部导航栏切换 目录结构 index为入口页主体,sub1-4为要切换的子页面 ...
- device tree --- #address-cells and #size-cells property【转】
转自:http://www.cnblogs.com/youchihwang/p/7050846.html device tree source Example1 / { #address-cells ...
- 读书笔记 effective c++ Item 28 不要返回指向对象内部数据(internals)的句柄(handles)
假设你正在操作一个Rectangle类.每个矩形可以通过左上角的点和右下角的点来表示.为了保证一个Rectangle对象尽可能小,你可能决定不把定义矩形范围的点存储在Rectangle类中,而是把它放 ...
- mac下---charles抓包https
网上找的很多安装包都有问题,终于找到个可用的! 下载地址: http://pan.baidu.com/s/1pLAONbX ———————————————————————————— 教程转载:htt ...
- Elasticsearch的相关知识
Elasticsearch的备份和恢复 http://keenwon.com/1393.html ETL kettle 数据转成json 发送POST请求 http://blog.csdn.net/a ...
- VS 2015 序列号/密钥/企业版/专业版
专业版:HMGNV-WCYXV-X7G9W-YCX63-B98R2企业版:HM6NR-QXX7C-DFW2Y-8B82K-WTYJV
- python开发学习-day14(jquery、ajax等)
s12-20160421-day14 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
- Rookey.Frame企业级快速开发框架开源了
Rookey.Frame是一套基于.NET MVC + easyui的企业级极速开发框架,支持简单逻辑模块零代码编程.支持工作流(BPM).支持二次开发,具有高扩展性.高复用性.高伸缩性:应广大网友要 ...
- 解决Python爬虫使用requests包控制台输出乱码问题
输出爬取的信息为乱码! 解决办法 爬取下来的编码是ISO-8859-1格式,需要转化为utf-8格式,加一句response.encoding = "utf8"