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

http://hihocoder.com/problemset/problem/1497

题意理解:看横坐标一样有多少对,当然还有纵坐标,i-j和i+j

急转弯:计算复杂度,因为最后有100000个旗子,并且他们的坐标很大,所以统计的时候要用map

算法:无

数据结构:map,在python中有dict


from __future__ import print_function

#
#

'test for map'

__author__ = 'hjkruclion'

import functools
import sys
import io
import copy

def read_int():
    """Read a seris of numbers."""
    return list(map(int, sys.stdin.readline().split()))

n = read_int()[0]
a = {}
b = {}
c = {}
d = {}
for x in range(n):
    t = read_int()
    i = copy.copy(t[0])
    j = copy.copy(t[1])
    # print(i)
    a[i] = a.get(i, 0) + 1
    b[j] = b.get(j, 0) + 1
    c[i + j] = c.get(i + j, 0) + 1
    d[i - j] = d.get(i - j, 0) + 1
res = 0
for (_, x) in a.items():
    res += x * (x - 1)
for (_, x) in b.items():
    res += x * (x - 1)
for (_, x) in c.items():
    res += x * (x - 1)
for (_, x) in d.items():
    res += x * (x - 1)
print(int(res/2))



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值