Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点
题意:有n (1 ≤ n ≤ 200 000) 个点,问有多少个点的开平方距离与横纵坐标的绝对值之差的和相等;
即
= |xi - xj| + |yi - yj|.(|xi|, |yi| ≤ 109)
思路:开始想的是容斥原理,即按x,y分别排序,先计算同x的点,然后在计算同y的点,这时由于相同的点之间的连边已经算过了,这样就不能再算。并且同一个y的点中可以每个点有多个点,算是不好编码的(反正我敲了很久..WA了)
反思:上面的容斥原理是从总体的思路来考虑的,这道题的难点也就是不重不漏。那么我们就模拟题目输入来往平面加点即可;每次加入一个点时,看与其同x,y有多少个点,这时由于当前点加了两次所以减去即可;坐标值较大,用map表示即可;
时间复杂度O(n)
#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
map<int,int> x,y;
map<pair<int,int>,int> mp; int main()
{
int n,x,y;
ll ans=;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&x,&y);
ans += x[a] + y[b] - mp[MK(a,b)];
x[a]++;
y[b]++;
mp[MK(a,b)]++;
}
printf("%I64d\n",ans);
}
Codeforces Round #345 (Div. 1) A. Watchmen 模拟加点的更多相关文章
- 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 (数学,map)
题意:给你\(n\)个点,求这\(n\)个点中,曼哈顿距离和欧几里得距离相等的点对数. 题解: 不难发现,当两个点的曼哈顿距离等于欧几里得距离的时候它们的横坐标或者纵坐标至少有一个相同,可以在纸上画一 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- 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 #345 (Div. 2)
DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...
- Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集
题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...
- Codeforces Round #345 (Div. 2) C (multiset+pair )
C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #345 (Div. 1) E. Clockwork Bomb 并查集
E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...
随机推荐
- LINUX怎么远程连接ORACLE数据库
A电脑装了ORACLE客户端,B是ORACLE服务器,都在LINUX环境下,请问A电脑怎么访问B上的数据库?该怎么改配置?求高手解答,越详细越好 很简单,你在A电脑安装一个ORACLE 客户端,然后, ...
- java_利用session校验图片认证码
RegisterServlet:检验server,client验证码是否一致 ImageServlet: 产生验证码 <!DOCTYPE html> <html> <he ...
- 内网架设SVN服务器相关设置
环境说明: 外网IP为静态IP,工作室内有多台电脑,公用一台路由器.想要在某台电脑上架设SVN服务器,方便团队开. 解决方案: 一.准备工作1.获取 Subversion 服务器程序到官 ...
- Tomcat启动报错org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["http-apr-8080"]”
1.使用netstat查看端口8080的使用情况: netstat -ano | findstr 8080 结果为: 最后一列表示使用8080端口的进程PID,如果返回结果为空则说明没有被使用. 2. ...
- Android_Notification
xml文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...
- Swift基础学习01
相关网站:http://www.cnblogs.com/tt_mc/p/3871295.html 相关辅助操作: 可以在右边直接查看输出值 可能出现的常见问题: 1.凡是=注意左右间距一样 2 ...
- 函数textread
函数textread可以按列读取ascii 文件中的元素,每一列中可能含有不同的数据类型.这函数读取其他程序生成的数据表时非常地有用. 实际应用中也要经常要读取txt文件,这个时候就需要用到强大的te ...
- UVA 11021 - Tribles(概率)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=481&page=s ...
- 配置Linux数据转发(给其他接口转发一个接口的internet网络)
配置Linux数据转发 [主机]第一步开启转发net.ipv4.ip_forward = 1echo "1" > /proc/sys/net/ipv4/ip_forward第 ...
- 【C语言】03-printf和scanf函数
一.printf函数 这是在stdio.h中声明的一个函数,因此使用前必须加入#include <stdio.h>,使用它可以向标准输出设备(比如屏幕)输出数据 1.用法 1> pr ...