hihocoder1497 Queen Attack

时间限制:10000ms
单点时限:1000ms
内存限制:256MB
描述
There are N queens in an infinite chessboard. We say two queens may attack each other if they are in the same vertical line, horizontal line or diagonal line even if there are other queens sitting between them.

Now given the positions of the queens, find out how many pairs may attack each other?

输入
The first line contains an integer N.

Then N lines follow. Each line contains 2 integers Ri and Ci indicating there is a queen in the Ri-th row and Ci-th column.

No two queens share the same position.

For 80% of the data, 1 <= N <= 1000

For 100% of the data, 1 <= N <= 100000, 0 <= Ri, Ci <= 1000000000

输出
One integer, the number of pairs may attack each other.

样例输入
5
1 1
2 2
3 3
1 3
3 1
样例输出
10

题意:同一对角线,水平线,垂线的皇后之间会相互攻击,给出n个皇后问有几对会相互攻击

题解:同一水平线的皇后y相等,同一垂线的皇后X相等,同一斜对角线的X+Y(/) 同一对角线的X-Y相等(\)

#include <bits/stdc++.h>
using namespace std;
map<int ,long long>mp[4];
int main()
{
    int T,i,x,y;
    long long ans = 0;
    cin>>T;
    while(T--){
        cin>>x>>y;
        mp[0][x]++;
        mp[1][y]++;
        mp[2][x+y]++;
        mp[3][y-x]++;
    }
    for(i=0;i<4;i++)
    for(map<int, long long>::iterator it = mp[i].begin();it != mp[i].end();it++)
        ans += (it->second)*(it->second-1)/2;
    cout<<ans<<endl;
    return 0;
} 
时间: 2024-10-09 19:07:49

hihocoder1497 Queen Attack的相关文章

hihoCoder 第255周 hiho一下 Queen Attack

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 There are N queens in an infinite chessboard. We say two queens may attack each other if they are in the same vertical line, horizontal line or diagonal line even if there are other queens sitting between them.

微软2017年预科生计划在线编程笔试第二场 Queen Attack

排序. 分别按照$x$,$y$以及对角线排序,统计一下方案数就可以了. #include<bits/stdc++.h> using namespace std; int n; struct X { int x,y; }s[100010]; bool cmp1(X a, X b) { return a.x<b.x; } bool cmp2(X a, X b) { return a.y<b.y; } bool cmp3(X a, X b) { return a.x+a.y<b.x

Uva 10401 Injured Queen Problem ( 计数DP)

Problem I Injured Queen Problem Input: standard input Output: standard output Time Limit: 6 seconds Memory Limit: 32 MB Chess is a two-player board game believed to have been played in India as early as the sixth century. However, in this problem we

hihocoder-1497-Queen Attack

#1497 : Queen Attack 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 There are N queens in an infinite chessboard. We say two queens may attack each other if they are in the same vertical line, horizontal line or diagonal line even if there are other queens s

uva 11195 Another queen (用状态压缩解决N后问题)

题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2136 Problem A Another n-Queen Problem I guess the n-queen problem is known by every person who has studied backtracking. In this problem you s

ZOJ 2587 Unique Attack 判断最小割是否唯一

很裸的判断最小割是否唯一.判断方法是先做一遍最大流求最小割,然后从源点和汇点分别遍历所有能够到达的点,看是否覆盖了所有的点,如果覆盖了所有的点,那就是唯一的,否则就是不唯一的. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostr

【树状数组区间修改单点查询】HDU 4031 Attack

http://acm.hdu.edu.cn/showproblem.php?pid=4031 [题意] 有一个长为n的长城,进行q次操作,d为防护罩的冷却时间,Attack表示区间a-b的墙将在1秒后受到攻击, 询问表示计算第a块墙受到攻击的次数,被防护罩抵消的不算 [思路] 总的攻击次数-防护罩抵消的次数 总的攻击次数可以树状数组维护 防护罩抵消的模拟 [AC] 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long l

dwr的A request has been denied as a potential CSRF attack.错误

虽然DWR是个很早就出现的Ajax框架,但一直都没去使用过,今天正好没事就看了一下并参照文档照做了个demo, 在其中碰到一个问题: 后台打印出错误信息:"严重: A request has been denied as a potential CSRF attack." 在网上google一把 之后,出现此错误的原因大都是说"请求被拒绝,可能存在csrf(cross-site request forgeries,跨站请求伪造)攻击. 页面URL可能被跨站了的服务所调用之类的

ASP.NET Padding Oracle Attack EXP

#!/usr/bin/perl## PadBuster v0.3 - Automated script for performing Padding Oracle attacks# Brian Holyfield - Gotham Digital Science ([email protected])## Credits to J.Rizzo and T.Duong for providing proof of concept web exploit# techniques and S.Vaud