【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D
传送门
题意:给你一条直线的斜率a和截距b,和某一时刻n个在直线上的点的横坐标,以及沿坐标轴方向的速度。问你这些点在(-∞,+∞)的时间内的碰撞次数。
solution
设两个点在t时刻相碰,有:
消去t,可以得到
而在直线上有
进一步整理可以得到
也就是说 当两个点的 vy−avxvy−avx 值相等时,两个点就会相碰
开一个map记录每一个 vy−avxvy−avx 值对应的点的数量
同时也要注意,如果两个点具有相同的vxvx vyvy ,它们的vy−avxvy−avx 也是相同的,但此时两个点相对静止 不会相碰
所以每次统计答案时,除了加上与当前点vy−avxvy−avx 相同的点的数量,还要减去与当前点相对静止的点的数量(可以另开一个map记录一下)
#define IN_LB() freopen("C:\\Users\\acm2018\\Desktop\\in.txt","r",stdin)
#define OUT_LB() freopen("C:\\Users\\acm2018\\Desktop\\out.txt","w",stdout)
#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
map<ll,int> mp;
map<pll,int> same;
int main() {
// IN_LB();
ll n,a,b,ans=0;
scanf("%lld%lld%lld",&n,&a,&b);
for(int i=0; i<n; i++) {
ll x,vx,vy;
scanf("%lld%lld%lld",&x,&vx,&vy);
ll res = vy-a*vx;
pll node = {vx,vy};
ans+=mp[res] - same[node];
mp[res]++;
same[node]++;
}
printf("%lld\n",ans*2);
return 0;
}
【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D的更多相关文章
- 容斥 + 组合数学 ---Codeforces Round #317 A. Lengthening Sticks
Lengthening Sticks Problem's Link: http://codeforces.com/contest/571/problem/A Mean: 给出a,b,c,l,要求a+x ...
- 【推导】Codeforces Round #478 (Div. 2) D. Ghosts
题意:给你一条直线以及初始时刻这条直线上的一些人的坐标,以及他们的速度矢量.让你对每个人计算他在过去无限远到将来无限远的时间内会与多少人处于同一个点,然后对每个人的这个值求和. 列方程组:两个人i,j ...
- 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 #589 (Div. 2)-E. Another Filling the Grid-容斥定理
Codeforces Round #589 (Div. 2)-E. Another Filling the Grid-容斥定理 [Problem Description] 在\(n\times n\) ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...
- Codeforces Round #450 (Div. 2)
Codeforces Round #450 (Div. 2) http://codeforces.com/contest/900 A #include<bits/stdc++.h> usi ...
随机推荐
- 前端:Jquery 处理同一Name的Radio组时,绑定checked属性异常的问题.(已解决)
将: $("input[type=radio][name=optionsContractGroup][value=201]").attr("checked",t ...
- Bootstraptable源码
// @author 文志新 http://jsfiddle.net/wenyi/47nz7ez9/3/ /**关于插件的通用构造 * * 构造函数PluginName($trigger,option ...
- python之string模块常量:数字,26个字母,标点符号,空白
In [8]: import string In [9]: dir(string) In [10]: string.ascii_letters Out[10]: 'abcdefghijklmnopqr ...
- form表单总结
form表单是一个基础的表单控件,最近做扫码登陆使用到,在这里记录一下 <form action="url" method="get" target=&q ...
- Codeforces 746F Music in Car
Music in Car 用两个Set维护一下尺取的过程. #include<bits/stdc++.h> #define LL long long #define fi first #d ...
- Python交互图表可视化Bokeh:4. 折线图| 面积图
折线图与面积图 ① 单线图.多线图② 面积图.堆叠面积图 1. 折线图--单线图 import numpy as np import pandas as pd import matplotlib.py ...
- Windows 如何备份恢复Ubuntu系统文件
之前安装的Win10 + Ubuntu18.04双系统,Ubuntu由于特殊原因崩了,所以打算重装系统 但是进不去Ubuntu系统,Ubuntu中的文件无法备份 试了win10的优盘启动工具中的DG, ...
- java的conllections.sort排序
https://www.cnblogs.com/yw0219/p/7222108.html?utm_source=itdadao&utm_medium=referral
- win 10 slmgr.vbs -xpr 无法运行,被豆麦笔记打开解决方法
win 10 slmgr.vbs -xpr 无法运行,被豆麦笔记打开解决方法 删除这个豆麦笔记 如果之前已经在 控制面板 程序中卸载过,那么是找不到的,我们先运行 slmgr.vbs -xpr,这个时 ...
- python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性
python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性 inspect import inspect def fun(): pass inspect.ism ...