返回信息流更新:
假设有N的皇后。
我在处理第1个皇后的时候,就看从第2个皇后到最后一个皇后,有多少个皇后可以和第1个皇后攻击(三种方式,有一种满足即可)。有一个就count++。
处理第2个皇后的时候,就看从第3个皇后到最后一个皇后,有多少个皇后可以和第2个皇后攻击。有一个就count++。
一直处理到第N-1个皇后。
------------------------
## 我说下我的思路吧(最终0分),大家看看哪不对。。。
### 建一个二维数组pos[N][2] 放N个点的坐标
```Python
for i in 0到N-1
for j in i+1到N
if pos[i][0] == pos[j][0] // (垂直)
count++;
else if pos[i][1] == pos[j][1] // (平行)
count++;
else if (pos[j][1]-pos[i][1])/(pos[j][0]-pos[i][0]) 的绝对值 == 1
count++;
```
### 最后输出count
#### 我是帮同学做的,改了三次,都是0分。关键是我本地的测试用例都过了呀。。。
### 有没有大神说下我的思路哪里不对,或者提供几个边界用例。
# 这个问题想不明白,今晚真睡不好了!
这是一条镜像帖。来源:北邮人论坛 / cpp / #95055同步于 2017/4/8
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
今晚微软第一题(Queen Attack)
Tension1900
2017/4/8镜像同步10 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
就贴出来的这些看不出来问题,贴所有的源码。
用另一种去实现,构造随机点测试集,找个结果不同的case分析。
【 在 Tension1900 (【意涵团】科科) 的大作中提到: 】
: 我明白你意思。可是我那种思路不知道哪不对。
溢出是个问题,改下可以再去试试能不能ac
【 在 Tension1900 (【意涵团】科科) 的大作中提到: 】
: 我明白你意思。可是我那种思路不知道哪不对。
笔试结束了还可以去测试吗?
【 在 Daci 的大作中提到: 】
: 溢出是个问题,改下可以再去试试能不能ac
:
: 【 在 Tension1900 (【意涵团】科科) 的大作中提到: 】
: : 我明白你意思。可是我那种思路不知道哪不对。
:
我python ac了
横向、纵向、右上、左上四个方向四个map,最后C n 2算个数
```python
def c2(n):
return n * (n - 1) / 2
n = int(raw_input())
queens = list()
vertical = {}
horizontal = {}
diagonal1 = {}
diagonal2 = {}
for i in range(n):
_input = raw_input().split()
_input0 = int(_input[0])
_input1 = int(_input[1])
queens.append((_input[0], _input[1]))
if _input0 in vertical:
vertical[_input0] += 1
else:
vertical[_input0] = 1
if _input1 in horizontal:
horizontal[_input1] += 1
else:
horizontal[_input1] = 1
if (_input0 >= _input1):
point = (_input0 - _input1, 0)
else:
point = (0, _input1 - _input0)
if point in diagonal1:
diagonal1[point] += 1
else:
diagonal1[point] = 1
if (_input0 + _input1) in diagonal2:
diagonal2[(_input0 + _input1)] += 1
else:
diagonal2[(_input0 + _input1)] = 1
cnt = 0
for k in vertical:
if vertical[k] >= 2:
cnt += c2(vertical[k])
for k in horizontal:
if horizontal[k] >= 2:
cnt += c2(horizontal[k])
for k in diagonal1:
if diagonal1[k] >= 2:
cnt += c2(diagonal1[k])
for k in diagonal2:
if diagonal2[k] >= 2:
cnt += c2(diagonal2[k])
print cnt
```
多谢多谢。
【 在 Daci 的大作中提到: 】
: hiho搜题目就可以做了
:
: 【 在 Mrxiaobai (Mr.小白) 的大作中提到: 】
: : 笔试结束了还可以去测试吗?
: