题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数

由于有正负对角线 因此用两个数组分别保存每个主教写的 x-y 和 x+y

然后每个数组中扫描重复数字k ans加上kC2就行了

wa了两发的原因是没考虑到如果整个数组都是重复的 那要最后额外加一次

#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define INF 0x3f3f3f3f
#define mem(str,x) memset(str,(x),sizeof(str))
#define STOP puts("Pause");
using namespace std;
typedef long long LL; int n, node[], node2[];
LL ans; int main()
{
ans = ;
scanf("%d", &n);
for(int i = ; i <= n; i++){
int x, y;
scanf("%d%d", &x, &y);
node[i] = x - y;
node2[i] = x + y;
}
sort(node + , node + + n);
sort(node2 + , node2 + + n);
LL count = ;
for(int i = ; i <= n; i++){
if(node[i] == node[i-]) count++;
else{
ans += (count * (count - ) / );
count = ;
}
}
ans += (count * (count - ) / );
count = ;
for(int i = ; i <= n; i++){
if(node2[i] == node2[i-]) count++;
else{
ans += (count * (count - ) / );
count = ;
}
}
ans += (count * (count - ) / );
printf("%I64d\n", ans);
return ;
}

Codeforces Round #341 Div.2 B. Wet Shark and Bishops的更多相关文章

  1. Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks dp+矩阵加速

    题目链接: http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test2 se ...

  2. Codeforces Round #341 Div.2 C. Wet Shark and Flowers

    题意: 不概括了..太长了.. 额第一次做这种问题 算是概率dp吗? 保存前缀项中第一个和最后一个的概率 然后每添加新的一项 就解除前缀和第一项和最后一项的关系 并添加新的一项和保存的两项的关系 这里 ...

  3. Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even

    题意是得到最大的偶数和 解决办法很简单 排个序 取和 如果是奇数就减去最小的奇数 #include <cstdio> #include <cmath> #include < ...

  4. Codeforces Round #341 (Div. 2) E - Wet Shark and Blocks

    题目大意:有m (m<=1e9) 个相同的块,每个块里边有n个数,每个数的范围是1-9,从每个块里边取出来一个数组成一个数,让你求组成的方案中 被x取模后,值为k的方案数.(1<=k< ...

  5. Codeforces Round #341 (Div. 2)

    在家都变的懒惰了,好久没写题解了,补补CF 模拟 A - Wet Shark and Odd and Even #include <bits/stdc++.h> typedef long ...

  6. Codeforces Round #341 (Div. 2) ABCDE

    http://www.cnblogs.com/wenruo/p/5176375.html A. Wet Shark and Odd and Even 题意:输入n个数,选择其中任意个数,使和最大且为奇 ...

  7. Codeforces Round #341 (Div. 2)B

    B. Wet Shark and Bishops time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. Codeforces Round #341 (Div. 2) D. Rat Kwesh and Cheese 数学

    D. Rat Kwesh and Cheese 题目连接: http://www.codeforces.com/contest/621/problem/D Description Wet Shark ...

  9. Codeforces Round #341 (Div. 2)A

    A. Wet Shark and Odd and Even time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. 3D几何变换

    3D点:非齐次坐标x(x,y,z) (x表示向量矢量) 齐次坐标:x~=(x~,y~,z~,w~)=w~(x,y,z,1)=w~x~         增广矢量:x—=(x,y,z,1) w~=0时,齐 ...

  2. 微信Auth2.0授权的时候出现两次回调

    在获取用户OpenID的时候 $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".WX_APPID. ...

  3. html input节点很多 json字符串提交解决方法

    遇到一个页面,38个input节点,页面前端写好的,不太容易改成 js框架 容易操作的样式,只能自己想办法一个一个id获取然后 setvalue getvalue(miniui): 38个一个一个写太 ...

  4. 内存对齐 和 sizeof小结

    数据对齐(内存对齐)指该数据所在的地址必须是该数据长度的整数倍.X86CPU能直接访问对齐的数据,当它试图访问未对齐的数据时,会在内部进行一系列的调整,降低运行速度.数据对齐一般出现在结构体和类中,在 ...

  5. Hadoop程序运行中的Error(1)-Error: org.apache.hadoop.hdfs.BlockMissingException

    15/03/18 09:59:21 INFO mapreduce.Job: Task Id : attempt_1426641074924_0002_m_000000_2, Status : FAIL ...

  6. header、footer、hgroup、address

    header:整个页面或者一个块级区域的头部区域,通常用来放置标题等信息: footer:整个页面或者一个块级区域的底部区域,通常用来放置版权信息.联系方式等: hgroup:用来对属于一个块级区域的 ...

  7. 【转】深入理解JavaScript闭包闭包(closure) (closure)

    一.什么是闭包?"官方"的解释是:闭包是一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分.相信很少有人能直接看懂这句话,因为他描述 ...

  8. UVA 1151二进制枚举子集 + 最小生成树

    题意:平面上有n个点(1<=N<=1000),你的任务是让所有n个点连通,为此, 你可以新建一些边,费用等于两个端点的欧几里得距离的平方.另外还有q(0<=q<=8)个套餐(数 ...

  9. dom扩展

    第十一章 DOM扩展 一.选择符API 1.querySelector()方法             接收一个CSS选择符,返回与该模式匹配的第一个元素,如果没有找到匹配的元素,返回null. 2. ...

  10. Dijksktra(测试源代码)

    1.此程序为c++程序 2.以下代码可实现手动输入,即去掉代码中的/*...*/注释符,并同时去掉赋值代码段 3.源代码 #include<iostream> using namespac ...