【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 ...
随机推荐
- Django中model层详解
#!/usr/bin/env python# _*_ coding:utf-8 _*_ from django.db import models class UserType(models.Model ...
- net core体系-web应用程序-4net core2.0大白话带你入门-4asp.net core配置项目访问地址
asp.net core配置访问地址 .net core web程序,默认使用kestrel作为web服务器. 配置Kestrel Urls有四种方式,我这里只介绍一种.其它方式可自行百度. 在Pr ...
- net core体系-API-1Ocelot-(1)概要
从这篇开始探讨Ocelot,Ocelot是一个.NET API网关,仅适用于.NET Core,用于.NET面向微服务/服务的架构中.当客户端(web站点.ios. app 等)访问web api时, ...
- Bootstrap 框架、插件
Bootstrap,前端工程师比较常用的框架.插件,根据它的定义,我们不妨这样理解,Bootstrap就是用于前端开发的一个模板,就是别人做好了我们直接可以搬过来直接使用或者根据自己需要略加修改设计自 ...
- 011 SpringSecurity的基本原理
一:securuty默认情况 1.默认的配置 在引用security依赖以后,会有一个配置 security.basic.enabled=true 2.启动 用户名:user 密码:在控制台上查看 3 ...
- python 操作mongo
1. 导包: import pymongo 2. 建立连接 client = pymongo.MongoClient("127.0.0.1",27017) 3. 获取数据库 db ...
- scala-Unit-3-Scala基础语法2
一.定义方法.函数.及方法转换为函数 1.方法的定义: def 方法名(参数1:数据类型,参数2:数据类型...):返回值类型 ={ } 2.定义函数: val h1 = (a:Int,b:Int) ...
- C语言中的模运算-hdu6124(打表,找规律)
题目链接:https://vjudge.net/problem/HDU-6124 题目描述: 题目大意就是给你一个数,判断这个数 % 其它数后共有几种结果. 这题对我来说最大的难点是我不太知道每个数 ...
- JAVA基础中的注意点(一)
1.标识符 标识符:标识某些事物用于区分的符号. (即区分某些事物的符号) 四条硬性规定: a.不能是 关键字.true.false.null. b.可以包含 字母.数字(0-9).下划线(_)或美 ...
- Oracle no TOP, how to get top from order
On ROWNUM and Limiting Results Our technologist explains how ROWNUM works and how to make it work fo ...