Codeforces Round #341 Div.2 B. Wet Shark and Bishops
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #341 Div.2 B. Wet Shark and Bishops相关的知识,希望对你有一定的参考价值。
题意:处在同一对角线上的主教(是这么翻译没错吧= =)会相互攻击 求互相攻击对数
由于有正负对角线 因此用两个数组分别保存每个主教写的 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[200010], node2[200010]; LL ans; int main() { ans = 0; scanf("%d", &n); for(int i = 1; i <= n; i++){ int x, y; scanf("%d%d", &x, &y); node[i] = x - y; node2[i] = x + y; } sort(node + 1, node + 1 + n); sort(node2 + 1, node2 + 1 + n); LL count = 1; for(int i = 2; i <= n; i++){ if(node[i] == node[i-1]) count++; else{ ans += (count * (count - 1) / 2); count = 1; } } ans += (count * (count - 1) / 2); count = 1; for(int i = 2; i <= n; i++){ if(node2[i] == node2[i-1]) count++; else{ ans += (count * (count - 1) / 2); count = 1; } } ans += (count * (count - 1) / 2); printf("%I64d\n", ans); return 0; }
以上是关于Codeforces Round #341 Div.2 B. Wet Shark and Bishops的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #341 (Div. 2)
Codeforces Round #341 Div.2 B. Wet Shark and Bishops
Codeforces Round #341 Div.2 C. Wet Shark and Flowers
Codeforces Round #341 Div.2 A. Wet Shark and Odd and Even
Codeforces Round #341 (Div. 2) E. Wet Shark and Blocks(矩阵优化DP)
Codeforces Round #341 (Div. 2) C. Wet Shark and Flowers(简单容斥)