【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 ...
随机推荐
- Linux 的文件类型
Linux 的文件通常分为 7 大类 文件类型 缩写 英文名称 ...
- Python_部分内置函数
内置函数:可以直接调用的函数 all():传入的列表,元组,等等,只要一个为假,就为假(fales)(所有的都为真才为真) # None, {}:空字典, []:空列表, 0:零,():空集合,“”: ...
- Codeforces 1045C Hyperspace Highways (看题解) 圆方树
学了一下圆方树, 好神奇的东西呀. #include<bits/stdc++.h> #define LL long long #define fi first #define se sec ...
- Codeforces 219E Parking Lot 线段树
Parking Lot 线段树区间合并一下, 求当前要占的位置, 不包括两端点的写起来方便一点. #include<bits/stdc++.h> #define LL long long ...
- Codeforces 596D Wilbur and Trees dp (看题解)
一直在考虑, 每一段的贡献, 没想到这个东西能直接dp..因为所有的h都是一样的. #include<bits/stdc++.h> #define LL long long #define ...
- TensorFlow图像预处理-函数
更多的基本的API请参看TensorFlow中文社区:http://www.tensorfly.cn/tfdoc/api_docs/python/array_ops.html 下面是实验的代码,可以参 ...
- B2B、B2C、C2C、O2O
B2B:企业对企业 B2B (也有写成 BTB)是指企业对企业之间的营销关系,它将企业内部网,通过 B2B 网站与客户紧密结合起来,通过网络的快速反应,为客户提供更好的服务,从而促进企业的业务发展(B ...
- 做项目单个功能的时候要理解需求和sql语句。
做项目单个功能的时候要理解需求和sql语句.最好直接按照给出来的sql语句或者存储过程来写,避免有极其细微的差别所造成的不同. 做宜春国税二期的时候有个功能叫夜间开票情况,钻取明细时由于没理解sql语 ...
- ul无点标签左移
ul标签去除掉点,ul li 块仍会在原来的位置,即与上一块内容相对右移一点. 这是 ul标签的默认padding值导致的. 修改style或者CSS中的class为如下即可 { list-style ...
- 003.DNS主从正反解析部署
一 实验环境 1.1 实验需求 配置正向解析bind 配置反向解析bind 配置辅助dns的bind 实现主辅dns之间的区域传送 1.2 环境规划 主dns:CentOS6.8-01 172.24. ...