codeforces Codeforces 650A Watchmen
题意:两点(x1,y1), (x2,y2)的曼哈顿距离=欧几里得距离
也就是:x1=x2或y1=y2,再删除重合点造成的重复计数即可。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <stack>
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
using namespace std;
const int maxn=;
const int inf=0x3f3f3f3f;
struct node{
LL x,y;
}a[maxn];
bool cmp1(node a,node b){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
} bool cmp2(node a,node b){
if(a.y==b.y) return a.x<b.x;
return a.y<b.y;
} int n;
// int a[maxn],b[maxn];
int main(){
scanf("%d",&n);
LL sum=;
for(int i=;i<n;i++){
scanf("%I64d%I64d",&a[i].x,&a[i].y);
}
sort(a,a+n,cmp1);
LL sum1=;
for(int i=;i<n;i++){
int j=i;
sum1=;
while(j<n&&a[i].x==a[j].x){
sum1++;
j++;
}
i=j-;
sum+=sum1*(sum1-)/;
}
sort(a,a+n,cmp2);
sum1=;
for(int i=;i<n;i++){
int j=i;
sum1=;
while(j<n&&a[i].y==a[j].y){
sum1++;
j++;
}
i=j-;
sum+=sum1*(sum1-)/;
}
sum1=;
for(int i=;i<n;i++){
int j=i;
sum1=;
while(j<n&&a[i].y==a[j].y&&a[j].x==a[i].x){
sum1++;
j++;
}
i=j-;
sum-=sum1*(sum1-)/;
}
printf("%I64d\n",sum);
return ;
}
codeforces Codeforces 650A Watchmen的更多相关文章
- Codeforces Codeforces Round #484 (Div. 2) E. Billiard
Codeforces Codeforces Round #484 (Div. 2) E. Billiard 题目连接: http://codeforces.com/contest/982/proble ...
- Codeforces Codeforces Round #484 (Div. 2) D. Shark
Codeforces Codeforces Round #484 (Div. 2) D. Shark 题目连接: http://codeforces.com/contest/982/problem/D ...
- (水题)Codeforces - 650A - Watchmen
http://codeforces.com/contest/650/problem/A 一开始想了很久都没有考虑到重复点的影响,解欧拉距离和曼哈顿距离相等可以得到 $x_i=x_j$ 或 $y_i=y ...
- Codeforces 650A Watchmen
传送门 time limit per test 3 seconds memory limit per test 256 megabytes input standard input output st ...
- CodeForces 651 C Watchmen
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- codeforces 650 C. Watchmen(数学公式)
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- 【CodeForces - 651C 】Watchmen(map)
Watchmen 直接上中文 Descriptions: 钟表匠们的好基友马医生和蛋蛋现在要执行拯救表匠们的任务.在平面内一共有n个表匠,第i个表匠的位置为(xi, yi). 他们需要安排一个任务计划 ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement set
C. Replacement Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/proble ...
- Codeforces Codeforces Round #316 (Div. 2) C. Replacement 线段树
C. ReplacementTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/570/problem ...
随机推荐
- 贪心算法:旅行商问题(TSP)
TSP问题(Traveling Salesman Problem,旅行商问题),由威廉哈密顿爵士和英国数学家克克曼T.P.Kirkman于19世纪初提出.问题描述如下: 有若干个城市,任何两个城市之间 ...
- 九度OJ 1042 Coincidence -- 动态规划(最长公共子序列)
题目地址:http://ac.jobdu.com/problem.php?pid=1042 题目描述: Find a longest common subsequence of two strings ...
- linux一部分常用的命令
如今的web项目,一般在windows下开发,然后部署在linux上.搜索了一下原因,大概是说,linux免费,此外,linux长时间运行都没有问题,可以达到1到2年不停机.因此,需要学习一些常用的l ...
- linux删除、读取文件原理
linux删除文件原理 LINUX的文件名是存在父目录的block里面,并指向这个文件额inode节点,这个文件的inode节点再标记指向存放这个文件的block的数据块.我们删除一个文件,实际上并不 ...
- ubuntu mint 15 编译安装PHP开发环境
php 5.3.5(download zip) httpd 2.2.24(download zip) mysql: apt-get install mysql step 1: install mysq ...
- 高效线程池之无锁化实现(Linux C)
from:http://blog.csdn.net/xhjcehust/article/details/45844901 笔者之前练手写过一个小的线程池版本(已上传至https://github.co ...
- jQuery选择器(适合初学者哟....)
选择器是jQuery最基础的东西,本文中列举的选择器基本上囊括了所有的jQuery选择器,也许各位通过这篇文章能够加深对jQuery选择器的理解,它们本身用法就非常简单,我更希望的是它能够提升个人编写 ...
- 学习PHP 301跳转的方法
发布:JB01 来源:脚本学堂 [大 中 小]本文详细介绍了,在php编程中实现301跳转,即301永久重定向的方法,感兴趣的朋友可以参考学习下. 本文转自:http://www.jbxu ...
- WPF窗体置于桌面最底层
在WPF中设置窗体的Topmost属性可以将窗体永远置于顶部,但是没有提供Bottommost属性将窗体置底.若果要将窗体置于桌面的最底部,就需要使用Windows API来实现了.解决方案如下: 1 ...
- asp.net mvc 发送邮箱验证码
public ActionResult Index() { /*第一种,利用Google的smtp来发送邮件*/ SmtpClient client = ); Random Rdm = new Ran ...