Codeforces #345 div1 A. Watchmen 数学
2016-03-09 19:01
405 查看
题目
题目链接:http://codeforces.com/contest/650/problem/A题目来源:http://codeforces.com/contest/650
简要题意:求平面上欧几里得距离等于曼哈顿距离的点对个数。
题解
列出等式可以发现两点必然xx坐标相同或yy坐标相同或重合。用map去统计每行每列的个数然后记数。
由于重合的时候会同时在两次计算中出现,需要再减去,因而还要对每个点的个数记数。
代码
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <cstring> #include <stack> #include <queue> #include <string> #include <vector> #include <set> #include <map> #define fi first #define se second using namespace std; typedef long long LL; typedef pair<int,int> PII; // head LL cal(LL x) { return x * (x-1); } map<int, int> mapx, mapy; map<PII, int> ma; int main() { int n, x, y; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d%d", &x, &y); mapx[x]++; mapy[y]++; ma[make_pair(x, y)]++; } LL ans = 0; for (auto it : mapx) { ans += cal(it.se); } for (auto it : mapy) { ans += cal(it.se); } for (auto it : ma) { ans -= cal(it.se); } printf("%I64d\n", ans / 2); return 0; }
相关文章推荐
- poj2362 Square DFS剪枝
- BZOJ_P1228 [SDOI2009]E&D(博弈+SG函数+打表)
- BZOJ1711Dingin吃饭
- 魔方阵
- Android项目使用Ant多渠道打包(最新sdk)
- C++中this指针的用法详解 http://blog.chinaunix.net/uid-21411227-id-1826942.html
- yii2扩展yii2-imagine遇到的问题
- 数据库中的实例名和数据库名有什么不同?
- IOS压缩解压缩
- Ruby中如何识别13位的时间戳
- 一行代码设置UITableView分割线的长度
- BZOJ4416: [Shoi2013]阶乘字符串
- BootStrap入门_创建第一个例子
- c语言基础
- 蓝桥杯 基础练习 十六进制转十进制
- e
- c++ 抽象工厂与工厂混合写法
- Android动态加载进阶 代理Activity模式
- 【OpenGL】详解第一个OpenGL程序
- 整理github上的一些好的项目(C\C++\Java\PHP\Android\Linux\JS\CSS\iOS)