【微软2017年预科生计划在线编程笔试第二场 A】Queen Attack
2017-10-04 18:44
218 查看
【题目链接】:http://hihocoder.com/problemset/problem/1497
【题意】
给你n个皇后;
然后问你其中能够互相攻击到的皇后的对数;
皇后的攻击可以穿透;
【题解】
对角线的话
就把x+y和x-y占据;
然后把x行和y列占据了;
每次对输入的数据看看对角线和行和列有没有棋子;
有的话就加上相应的数目;
这个用map就能搞定;
可能会爆int
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define mp make_pair #define pb push_back #define fi first #define se second #define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii; typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1}; const int dy[9] = {0,0,0,-1,1,-1,1,-1,1}; const double pi = acos(-1.0); const int N = 2e4+100; int n; map <int,int> dic1,dic2,dic3,dic4; LL ans = 0; int main() { //freopen("F:\\rush.txt","r",stdin); ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use cin >> n; rep1(i,1,n) { int x,y; cin >> x >> y; ans+=dic1[x],ans+=dic2[y],ans+=dic3[x-y],ans+=dic4[x+y]; dic1[x]++,dic2[y]++,dic3[x-y]++,dic4[x+y]++; } cout << ans << endl; return 0; }
相关文章推荐
- 【微软2017年预科生计划在线编程笔试第二场 A】Queen Attack
- Queen Attack -- 微软2017年预科生计划在线编程笔试第二场
- 微软2017年预科生计划在线编程笔试第二场-#1497 : Queen Attack
- 微软2017年预科生计划在线编程笔试第二场-#1500 : EL SUENO
- 微软2017年预科生计划在线编程笔试第二场-#1499 : A Box of Coins
- 【微软2017年预科生计划在线编程笔试第二场 B】Diligent Robots
- 微软2017年预科生计划在线编程笔试第二场B题Diligent Robots
- 微软2017年预科生计划在线编程笔试第二场-#1498 : Diligent Robots
- 【微软2017年预科生计划在线编程笔试 B】Tree Restoration
- 【微软2017年预科生计划在线编程笔试 A】Legendary Items
- 微软2017年预科生计划在线编程笔试
- [hihocoder1489][微软2017年预科生计划在线编程笔试][Legendary Items]
- 微软2017年预科生计划在线编程笔试-#1491 : Monster Killing
- 微软2017年预科生计划在线编程笔试-#1490 : Tree Restoration
- 微软2017年预科生计划在线编程笔试 题目1 : Legendary Items
- 微软2017年预科生计划在线编程笔试 A Legendary Items
- 微软2017年预科生计划在线编程笔试-#1489 : Legendary Items
- 微软2017年预科生计划在线编程笔试,附解题思路
- 微软2017年预科生计划在线编程笔试-#1492 : Parentheses Sequence
- 微软2017年预科生计划在线编程笔试题Legendary Items