题目:给你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的更多相关文章

  1. 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 ...

  2. Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点

    Watchmen 题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等: 即 = |xi - xj| + |yi - yj|.(|xi|, |y ...

  3. Codeforces Round #345 (Div. 1) A - Watchmen 容斥

    C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...

  4. Codeforces Round #345 (Div. 1) A. Watchmen (数学,map)

    题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数. 题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一 ...

  5. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  6. Codeforces #345 Div.1

    Codeforces #345 Div.1 打CF有助于提高做题的正确率. Watchmen 题目描述:求欧拉距离等于曼哈顿距离的点对个数. solution 签到题,其实就是求有多少对点在同一行或同 ...

  7. Codeforces Round #345 (Div. 2)

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. python函数 -- 作用域,异常处理

    1.def语句和参数 python定义函数的关键词为def,格式如下: def 函数名([变元],[变元],....)          #保存在变元中的值,在函数返回后该变元就会被销毁了. 2.返回 ...

  2. 在Ubuntu上安装Spark

    1.下载spark2.4.3 使用用户的hadoop的版本,解压并放到/usr/local下并改名为spark目录 2.设置spark目录为本用户所有 3.设置环境变量 (1)#~/.bashrc e ...

  3. Centos 安装Pycharm 并移动到桌面。

    版权声明:版权所有.未经同意不得转发,装载 https://blog.csdn.net/limingyue0312/article/details/81805826 1.下载pycharm软件包 网页 ...

  4. Java中this与super的区别

    this与super关键字在java中构造函数中的应用: ** super()函数 ** super()函数在子类构造函数中调用父类的构造函数时使用,而且必须要在构造函数的第一行,例如: class ...

  5. JS中的继承(下)

    JS中的继承(下) 在上一篇 JS中的继承(上) 我们介绍了3种比较常用的js继承方法,如果你没看过,那么建议你先看一下,因为接下来要写的内容, 是建立在此基础上的.另外本文作为我个人的读书笔记,才疏 ...

  6. python-queue队列-生产者消费者

    import threading,time import queue q = queue.Queue(maxsize=10) def Producer(name):#生产者 count=1 while ...

  7. Java后端技术面试汇总(第四套)

    1.Java基础 • 为什么JVM调优经常会将-Xms和-Xmx参数设置成一样:• Java线程池的核心属性以及处理流程:• Java内存模型,方法区存什么:• CMS垃圾回收过程:• Full GC ...

  8. Jquery table相关--工时系统

    1.jquery 的弹出对话框,单击事件之后 if (confirm("确定要删除?")) { // //点击确定后操作 } 2.对某个table中的checkbox是否被选中的遍 ...

  9. Yii2 增删查改

    查: User::find()->all();    //返回所有用户数据:User::findOne($id);   //返回 主键 id=1  的一条数据: User::find()-> ...

  10. es6编译器(babel搭建)

    1.安装Node.js,初始化项目 npm init -y 2.安装babel-cli(兼容至ie7) npm i @babel/core @babel/cli @babel/preset-env - ...