【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 ...
随机推荐
- [转] 一张图理解prototype、proto和constructor的三角关系
前面的话 javascript里的关系又多又乱.作用域链是一种单向的链式关系,还算简单清晰:this机制的调用关系,稍微有些复杂:而关于原型,则是prototype.proto和constructor ...
- reconnecting-websocket.js
websocket是HTML5下一个不错的网络协议解决方案,有一个场景很多猿猿都会遇到,手机锁屏后大约60秒,IOS会自动断开websocket连接,连接丢失了,那我们的数据也就断了.websocke ...
- 聊聊Docker数据卷和数据卷容器
当程序在容器运行的时候,特别是需要与其他容器中的程序或容器外部程序进行沟通交流,这时需要进行数据交换,作为常用的两种沟通数据的方式,网络通信与文件读写是需要提供给程序的支持, [数据卷] 文件是数据持 ...
- HDU1693 Eat the Trees 插头dp
原文链接http://www.cnblogs.com/zhouzhendong/p/8433484.html 题目传送门 - HDU1693 题意概括 多回路经过所有格子的方案数. 做法 最基础的插头 ...
- 存储过程导入excel
#region 导入订单 protected override string DoExcelData(System.Data.DataTable dt) { ...
- List接口相对于Collection接口的特有遍历方法
package com.hxl; import java.util.ArrayList; import java.util.List; public class Test { public stati ...
- 042 spring boot在启动之后,自动关闭
在学校数据源的时候,还没有开始使用数据源,项目就关闭了. 为了学习数据源,就只能使用测试类. 但是,最近需要使用restful进行测试的时候,项目是关闭的,就很糟糕,不好进行测试. 1.日志如下: D ...
- LoadRunner中 host-mapping的Capture Level说明
lr录制后空白,那么就要弄明白lr中host-mapping的Capture Level选项socket level data.winnet level data.socket level andwi ...
- spring security学习
https://www.cnblogs.com/leihenqianshang/articles/5313159.html
- maven聚合工程无法install
对于maven聚合工程,有时候执行maven命令进行mvn clean install时会出一些莫名奇妙的错误: 一直报告找不到符号,仔细看了项目源代码也不知道是什么原因.首先确保项目所在路径为英文路 ...