Codeforces Round #478 (Div. 2) D. Ghosts(几何)

2023-12-03 19:40

本文主要是介绍Codeforces Round #478 (Div. 2) D. Ghosts(几何),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

D. Ghosts

这里写图片描述

传送门

昨晚过掉前三题后看了眼D,噫….几何题,溜了溜了,准备明天(今天)的考试去了。

实际上这题只要思路对了操作起来其实很简单。
对于两个起始坐标分别为 (Xi,aXi+b)(Xj,aXj+b) ( X i , a X i + b ) 和 ( X j , a X j + b ) 的两个来说,他们两个在运动中碰撞当且仅当坐标相同,那么我们可以列出以下两条式子:

Xi+tVXi=Xj+tVXj X i + t V X i = X j + t V X j
aXi+b+tVYi=aXj+b+tVYj a X i + b + t V Y i = a X j + b + t V Y j

解方程得到 atVXjatVXi=tVYjtVYi a t V X j − a t V X i = t V Y j − t V Y i
VYiaVXi=VYjaVXj 化 简 得 到 V Y i − a V X i = V Y j − a V X j
与此同时,我们还可以得知合速度方向相同的点永远不会相撞,
那么最后的答案就是相同的值的个数减去对应的向量的个数。

#include<cstdio>
#include<iomanip>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<limits.h>
#include<string.h>
#include<map>
#include<list>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define eps double(1e-6)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1int n,a,b;struct edge
{ll x,vx,vy;
}p[200005];map<ll, ll >mp1;
map<pair<ll, ll> ,ll >mp2;int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cin>>n>>a>>b;mp1.clear();mp2.clear();for(int i=0;i<n;i++){cin>>p[i].x>>p[i].vx>>p[i].vy;ll x=p[i].x;ll vx=p[i].vx;ll vy=p[i].vy;mp1[vy-a*vx]++;mp2[make_pair(vx,vy)]++;}ll sum=0;for(int i=0;i<n;i++){ll x=p[i].x;ll vx=p[i].vx;ll vy=p[i].vy;sum+=mp1[vy-a*vx]-mp2[make_pair(vx,vy)];}cout<<sum<<endl;
}

这篇关于Codeforces Round #478 (Div. 2) D. Ghosts(几何)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/450650

相关文章

uva 10387 Billiard(简单几何)

题意是一个球从矩形的中点出发,告诉你小球与矩形两条边的碰撞次数与小球回到原点的时间,求小球出发时的角度和小球的速度。 简单的几何问题,小球每与竖边碰撞一次,向右扩展一个相同的矩形;每与横边碰撞一次,向上扩展一个相同的矩形。 可以发现,扩展矩形的路径和在当前矩形中的每一段路径相同,当小球回到出发点时,一条直线的路径刚好经过最后一个扩展矩形的中心点。 最后扩展的路径和横边竖边恰好组成一个直

poj 1113 凸包+简单几何计算

题意: 给N个平面上的点,现在要在离点外L米处建城墙,使得城墙把所有点都包含进去且城墙的长度最短。 解析: 韬哥出的某次训练赛上A出的第一道计算几何,算是大水题吧。 用convexhull算法把凸包求出来,然后加加减减就A了。 计算见下图: 好久没玩画图了啊好开心。 代码: #include <iostream>#include <cstdio>#inclu

uva 1342 欧拉定理(计算几何模板)

题意: 给几个点,把这几个点用直线连起来,求这些直线把平面分成了几个。 解析: 欧拉定理: 顶点数 + 面数 - 边数= 2。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc

XTU 1237 计算几何

题面: Magic Triangle Problem Description: Huangriq is a respectful acmer in ACM team of XTU because he brought the best place in regional contest in history of XTU. Huangriq works in a big compa

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

poj 3304 几何

题目大意:给出n条线段两个端点的坐标,问所有线段投影到一条直线上,如果这些所有投影至少相交于一点就输出Yes!,否则输出No!。 解题思路:如果存在这样的直线,过投影相交点(或投影相交区域中的点)作直线的垂线,该垂线(也是直线)必定与每条线段相交,问题转化为问是否存在一条直线和所有线段相交。 若存在一条直线与所有线段相交,此时该直线必定经过这些线段的某两个端点,所以枚举任意两个端点即可。

POJ 2318 几何 POJ 2398

给出0 , 1 , 2 ... n 个盒子, 和m个点, 统计每个盒子里面的点的个数。 const double eps = 1e-10 ;double add(double x , double y){if(fabs(x+y) < eps*(fabs(x) + fabs(y))) return 0 ;return x + y ;}struct Point{double x , y

poj 2653 几何

按顺序给一系列的线段,问最终哪些线段处在顶端(俯视图是完整的)。 const double eps = 1e-10 ;double add(double x , double y){if(fabs(x+y) < eps*(fabs(x) + fabs(y))) return 0 ;return x + y ;}struct Point{double x , y ;Point(){}Po

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op