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

题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数.
题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一画,当两点不满足上文所说的情况时,他们的曼哈顿距离一定大于直线距离,因为三角形的两边必定大于第三边,然后我们边输入边求,用桶分别存横和纵坐标,每次出现都将目前桶的值贡献给答案,但是两个相同的点应该只算一次贡献,我们要再开一个桶来减去重复的次数.
代码:
int n;
map<ll,ll> mpx,mpy;
map<PLL,ll> mp;
ll x,y;
ll ans; int main() {
// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
scanf("%d",&n);
for(int i=1;i<=n;++i){
scanf("%d %d",&x,&y);
ans+=mpx[x]+mpy[y]-mp[make_pair(x,y)];
mpx[x]++;mpy[y]++;mp[make_pair(x,y)]++;
}
printf("%lld\n",ans); return 0;
}
Codeforces Round #345 (Div. 1) A. Watchmen (数学,map)的更多相关文章
- 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
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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- Codeforces Round #345 (Div. 2)【A.模拟,B,暴力,C,STL,容斥原理】
A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- Codeforces Round #304 (Div. 2) D 思维/数学/质因子/打表/前缀和/记忆化
D. Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- Codeforces Round #207 (Div. 1)B(数学)
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include< ...
- Codeforces Round #499 (Div. 2) C. Fly(数学+思维模拟)
C. Fly time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
随机推荐
- Js中函数式编程的理解
函数式编程的理解 函数式编程是一种编程范式,可以理解为是利用函数把运算过程封装起来,通过组合各种函数来计算结果.函数式编程与命令式编程最大的不同其实在于,函数式编程关心数据的映射,命令式编程关心解决问 ...
- 关于spring-data与elasticsearch的使用,自定义repository
之前没有使用过spring-data,关于spring-data有很多很棒的设计,例如仅仅只需要声明一个接口就行,你甚至都不需要去实现,spring-data有内置默认的实现类,基本就上完成绝大多数对 ...
- [CPP] 智能指针
介绍 C++ 的智能指针 (Smart Pointers) 相关 API. C++ 中的智能指针是为了解决内存泄漏.重复释放等问题而提出的,它基于 RAII (Resource Acquisition ...
- 攻防世界 - Misc(一)
base64÷4: 1.下载附件,是一个.txt文件,打开是一串字符, 666C61677B453333423746443841334238343143413936393945444442413234 ...
- oracle关闭监听log.xml文件生成步骤
1.查看sqlnet.ora文件是否存在 cd $ORACLE_HOME/network/admin ls 如果不存在,copy一个过来 cp samples/sqlnet.ora . 2.修改sql ...
- allator 对springBoot进行加密
1.对springboot项目添加jar包和xml文件 allatori.xml: <config> <input> <jar in="target/sprin ...
- uni-app开发经验分享八: 实现微信APP支付的全过程详解
背景 最近项目使用uni-app实现微信支付,把过程简单记录下,帮助那些刚刚基础uni-app,苦于文档的同学们.整体来说实现过程和非uni-app的实现方式没有太大不同,难点就在于uni-app对于 ...
- php artisan db:seed 报错
在laravel 5中执行,要执行数据填充时报如下错误 php artisan db:seed 错误: [ReflectionException] Cla ...
- GRPC Health Checking Protocol Unavailable 14
https://github.com/grpc/grpc/blob/master/doc/health-checking.md GRPC Health Checking Protocol Health ...
- 接口 Interfaces
Interfaces - zope.interface 5.0.2.dev0 documentation https://zopeinterface.readthedocs.io/en/latest/ ...