Codeforces 975D
题意略。
思路:我们来写一下公式:
P1:(x1 + t * Vx1,y1 + t * Vy1) P2:(x2 + t * Vx2,y2 + t * Vy2)
x1 + t * Vx1 = x2 + t * Vx2
y1 + t * Vy1 = y2 + t * Vy2
a(x1 - x2) = t * (Vy2 - Vy1)
x1 - x2 = t * (Vx2 - Vx1)
a * (Vx2 - Vx1) = Vy2 - Vy1
说明满足a * Vx2 - Vy2 = a * Vx1 - Vy1这个式子的就可以相交。
这里要特殊考虑一下平行情况,我们要从所有贡献中减去平行的不合法情况,才能得到最终答案。注意,几个静止的点也是平行的。
详见代码:
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- LL n,a,b,vx,vy;
- map<LL,LL> mp;
- map<pair<LL,LL>,LL> mp1;
- int main(){
- scanf("%lld%lld%lld",&n,&a,&b);
- LL x;
- for(int i = ;i < n;++i){
- scanf("%lld%lld%lld",&x,&vx,&vy);
- LL s = a * vx - vy;
- ++mp[s];
- mp1[make_pair(vx,vy)]++;
- }
- map<LL,LL>::iterator it;
- LL sum = ;
- for(it = mp.begin();it != mp.end();++it){
- LL temp = it->second;
- LL contribute = temp * (temp - );
- sum += contribute;
- }
- map<pair<LL,LL>,LL>::iterator it1;
- for(it1 = mp1.begin();it1 != mp1.end();++it1){
- LL temp = it1->second;
- sum -= temp * (temp - );
- }
- printf("%lld\n",sum);
- return ;
- }
Codeforces 975D的更多相关文章
- Codeforces 975D. Ghosts
Description 给出一条直线 \(a*x+b\) 上的 \(n\) 个点,每一个点有一个速度 \((v_x,v_y)\),求 \(T=[-oo,oo]\) 相交的次数乘以 \(2\) 题面 S ...
- Codeforces Round #478 Div2 975A 975B 975C 975D
A. Aramic script 题目大意: 对于每个单词,定义一种集合,这个集合包含且仅包含单词中出现的字母.给你一堆单词,问有多少种这种集合. 题解: 状压,插入set,取size #in ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
随机推荐
- es6的基本用法
1. let和const <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- 第一篇:开始进入 django 之旅
文中所有示例代码的仓库地址:https://github.com/HelloGitHub-Team/HelloDjango-blog-tutorial 开发环境说明 本教程写作时开发环境的系统平台为 ...
- java多线程调用run和不调用run的区别
当在java程序中创建一个线程的时候,会三种情况: 1,只运行run方法 2,先执行start,再执行run方法 3,只运行start方法 三者的区别如下: 运行方式 区别 只运行run 只运行run ...
- PHP使用array_unique对二维数组去重处理
去重,点这里,东西是好东西,就是有点懒.莫见怪
- IBM RAD中集成Websphere启动后无法debug解决办法
问题描述: IBM Rational Application Developer for WebSphere软件在启动WebSphere的时候无法以debug模式启动,debug启动后显示为start ...
- DataGridView 的使用总结
一.属性应用 1.设置单元格鼠标点击后就进入编辑状态 设置DataGridView控件的EditMode这个属性,即 EditMode = System.Windows.Forms.DataGridV ...
- 1. 源码分析---SOFARPC可扩展的机制SPI
这几天离职在家,正好没事可以疯狂的输出一下,本来想写DUBBO的源码解析的,但是发现写DUBBO源码的太多了,所以找一个写的不那么多的框架,所以就选中SOFARPC这个框架了. SOFARPC是蚂蚁金 ...
- 夯实Java基础(七)——Static关键字
1.static介绍 static关键字一直是各大企业中面试常常会问到的问题,主要考察面试者的基础是否扎实,下面来介绍一下static关键字. Java中static表示“全局”或者“静态”的意思,可 ...
- python基础之循环与迭代器
循环 python 循环语句有for循环和while循环. while循环while循环语法 while 判断条件: 语句 #while循环示例 i = 0 while i < 10: i += ...
- 浅谈单例模式及其java实现
单例模式是23种设计模式中比较简单的一种,在此聊一下单例模式. 1.什么是设计模式? 对于没有接触过设计模式的人来说,一听到设计模式这四个字就觉得这个东西很高深莫测,一下子就对这个东西产生了恐惧感,其 ...