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

来源:互联网 发布:数据库设计原则,范式 编辑:程序博客网 时间:2024/05/16 11:32

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 functoolsimport sysimport ioimport copydef 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) + 1res = 0for (_, 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
原创粉丝点击