We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- NP Complete
- Spies, Revised
- Discussions
Spies, Revised
Spies, Revised
Sort by
recency
|
103 Discussions
|
Please Login in order to post a comment
Spies, Revised sounds like a fascinating topic, especially when it comes to uncovering hidden details and analyzing systems. I’ve dealt with something similar while navigating complex paperwork for NDIS Registration, where every small detail mattered. Working with an ndis registration consultant really helped me understand the right structure and compliance requirements without feeling overwhelmed. It made the whole process smoother and much clearer in the long run.
this is python 3
def is_colinear(r1, c1, r2, c2, r3, c3): return (r2 - r1) * (c3 - c1) == (r3 - r1) * (c2 - c1) def is_valid(row, col, placement): for r2 in range(row): c2 = placement[r2] if col == c2 or abs(row - r2) == abs(col - c2): return False for r1 in range(r2): c1 = placement[r1] if is_colinear(r1, c1, r2, c2, row, col): return False return True def solve(n, placement=[], used_cols=set()): row = len(placement) if row == n: return placement for col in range(n): if col in used_cols: continue if is_valid(row, col, placement): res = solve(n, placement + [col], used_cols | {col}) if res: return res return None if name == "main": max_n = 13
for n in range(max_n, 0, -2):
result = solve(n) if result: print(n) print(" ".join(str(c + 1) for c in result)) break
def is_colinear(r1, c1, r2, c2, r3, c3): return (r2 - r1) * (c3 - c1) == (r3 - r1) * (c2 - c1)
def is_valid(row, col, placement): for r2 in range(row): c2 = placement[r2] if col == c2 or abs(row - r2) == abs(col - c2): return False for r1 in range(r2): c1 = placement[r1] if is_colinear(r1, c1, r2, c2, row, col): return False return True
def solve(n, placement=[], used_cols=set()): row = len(placement) if row == n: return placement for col in range(n): if col in used_cols: continue if is_valid(row, col, placement): res = solve(n, placement + [col], used_cols | {col}) if res: return res return None
if name == "main": max_n = 13 for n in range(max_n, 0, -2): result = solve(n)
if result: print(n) print(" ".join(str(c + 1) for c in result)) break9
1 7 4 6 9 2 5 3 8
why this solution is not accepted?
There might be an error in code control, the following output matrix seems true.
"3 1 4 2 5"