计算几何 点对处理 #345 (Div. 2) C. Watchmen
题目:给你n(<=2*1e5)个点,求其中有多少个点对之间的连线向量平行坐标轴;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
#define MM(a,b) memset(a,b,sizeof(a));
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi=acos(-1);
const int mod=100000000;
ll max(ll a,ll b)
{return a>b?a:b;};
int min(int a,int b)
{return a<b?a:b;}; struct node{
int x,y;
}ne[200005]; bool cmpx(node a,node b)
{
if(a.x==b.x) return a.y<b.y;
else return a.x<b.x;
} bool cmpy(node a,node b)
{
if(a.y==b.y) return a.x<b.x;
else return a.y<b.y;
} bool operator ==(const node &a,const node &b)
{
return a.x==b.x&&a.y==b.y;
} int main()
{
int n,m;
while(~scanf("%d",&m))
{
for(int i=0;i<m;i++) scanf("%d %d",&ne[i].x,&ne[i].y); ll ans=0;
sort(ne,ne+m,cmpx);
for(int i=0;i<m-1;i++)
{
int cur=i;
while(ne[i+1].x==ne[cur].x&&(i+1)<m) i++;
ll k=i-cur+1;ans+=(k-1)*k/2;//注意k要ll型,不然k*k的时候会爆int
}
sort(ne,ne+m,cmpy);
for(int i=0;i<m-1;i++)
{
int cur=i;
while(ne[i+1].y==ne[cur].y&&(i+1)<m) i++;
ll k=i-cur+1;ans+=(k-1)*k/2;
}
for(int i=0;i<m;i++)
{
int cur=i;
while(ne[i]==ne[i+1]&&(i+1)<m) i++;
ll k=i-cur+1;ans-=k*(k-1)/2;
}//去重操作
printf("%lld\n",ans);
}
return 0;
}
分析:刚开始只考虑到只有一个点的重合,用了unique果断错,,,后来发现只要x和y两个方向
枚举。然后再去重减去相同的点之间的就可以了
计算几何 点对处理 #345 (Div. 2) C. Watchmen的更多相关文章
- Codeforces Round #345 (Div. 1) A. Watchmen
A. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点
Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...
- Codeforces Round #345 (Div. 1) A - Watchmen 容斥
C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...
- Codeforces Round #345 (Div. 1) A. Watchmen (数学,map)
题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数. 题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces #345 Div.1
Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...
- Codeforces Round #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- codeforces Codeforces Round #345 (Div. 1) C. Table Compression 排序+并查集
C. Table Compression Little Petya is now fond of data compression algorithms. He has already studied ...
- Codeforces Round #345 (Div. 1) B. Image Preview
Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed ...
随机推荐
- 创建Maven Web项目时很慢解决办法
点击加号,Name输入archetypeCatalog,Value输入internal archetypeCatalog表示插件使用的archetype元数据,不加这个参数时默认为remote,loc ...
- Smarty内置函数之config_load
config_load的作用是: 用于从配置文件中加载变量,属性file引入配置文件名,另外若配置文件包含多个部分,可以使用属性section指定从那部分取得变量(若不指定,将会引入失败). 实例: ...
- Momentum Contrast for Unsupervised Visual Representation Learning
Momentum Contrast for Unsupervised Visual Representation Learning 一.Methods Previously Proposed 1. E ...
- 安装PIG
下载Pig 能够执行在Hadoop 0.20.* http://mirror.bit.edu.cn/apache/pig/pig-0.11.1/pig-0.11.1.tar.gz 也能够依据你的Had ...
- 在set中放入自定义类型
这件事情的起因是在学习背包问题时突然想到了一种算法,分析了一下应该是n^2logn复杂度的,当然比dp慢.但是既然想到了就实现了下: #include<bits/stdc++.h> usi ...
- java中的全局变量、局部变量与静态常量的区别
java中的变量类型分类: 类变量:独立于方法之外的变量,用 static 修饰.实例变量:独立于方法之外的变量,不过没有 static 修饰.局部变量:类的方法中的变量.比如: public cla ...
- python之SSH远程登录
一.SSH简介 SSH(Secure Shell)属于在传输层上运行的用户层协议,相对于Telnet来说具有更高的安全性. 二.SSH远程连接 SSH远程连接有两种方式,一种是通过用户名和密码直接登录 ...
- linux基本操作和常用命令(2)
linux基本操作和常用命令(2) 第二部分主要是涉及到用户和组的概念,以及一些操作.涉及到用户和组的共三个文件,分别存放在/etc/shadow(密码信息) /etc/group(组信息) /etc ...
- auth
谨记:使用的任何框架在网上都会有对应的auth代码,多百度,直接引用插件就好了 tp5 auth 示例:https://blog.csdn.net/strugglm/article/details/7 ...
- 标准C语言(3)
操作符用来描述对数字的处理规则根据操作符所需要配合的数字个数把操作符分为单目操作符,双目操作符和三目操作符 C语言里用+,-,*和/表示加减乘除四则运算,它们都是双目操作符,如果参与除法计算的两个数字 ...