**Spies, Revised**

### Problem Statement :

Two spies in a grid will have their covers blown if: 1 . They are both in the same row. 2. They are both in the same column. 3. They can see each other diagonally (i.e., lie in a line inclined 45° or 135° to the base of the grid). The level of danger is now increased! In addition to the conditions above, no 3 spies may lie in any straight line. This line need not be aligned 45° or 135° to the base of grid. Write a program in the language of your choice to place N spies (one spy per row) on an N x N grid without blowing anyone's cover. Your program must then print the following 2 lines describing a valid configuration: 1. The value of N. 2. A space-separated list of 1-indexed column numbers, where each value i is the column number of the spy in row i (where 1 <= i <= N ). Solve this problem for N as large as possible, up to (and including) 999. Note: Run and Custom Input are not available for this challenge; you must click Submit Code for your submission to be scored. Your score for this challenge will always be the maximum value scored by any of your submissions. Examples In the examples below, S denotes a spy and * denotes an empty cell. Input Format There is no input for this challenge. Constraints N is odd. N < 1000 (Do not submit for any value of N larger than 999 ) Output Format Print the following 2 lines of output: 1. The first line should be a single integer denoting the value of N. 2 .The second line should contain a space-separated list of integers . Each integer i (where 1 < i <= N) should be the 1-indexed column number where the spy in row i is located.

### Solution :

` ````
Solution in C :
In Python3 : ( Problem has Ambiguity )
import random
n=11
list_of_numbers=[]
final_list=[]
rows=[]
colomns=[]
def check(a):
for k in final_list:
chk1=[]
chk2=[]
x=k[0]
y=k[1]
for i in range(n):
for j in range(n):
if i==j:
if [x+i,y+j] in final_list:
return 0
if [x-i,y-j] in final_list:
return 0
elif [x+i,y+j] in final_list:
chk1.append([x+i,y+j])
if len(chk1)>2:
return 0
elif [x-i,y-j] in final_list:
chk2.append([x-i,y-j])
if len(chk2)>2:
return 0
for i in range(n):
list_of_numbers.append(i)
def number_generator():
while(1):
r = random.choice(list_of_numbers)
c = random.choice(list_of_numbers)
if r not in rows and c not in colomns:
rows.append(r)
colomns.append(c)
final_list.append([c,r])
if len(final_list)==n:
break
number_generator()
while(1):
if not check(1):
final_list=[]
rows=[]
colomns=[]
number_generator()
else:
print(final_list)
new_list=[]
for i in final_list:
new_list.append(i[0]*n + (i[1]+1))
new_list.sort()
for i in new_list:
print(i, end=" ")
break
```

## View More Similar Problems

## Down to Zero II

You are given Q queries. Each query consists of a single number N. You can perform any of the 2 operations N on in each move: 1: If we take 2 integers a and b where , N = a * b , then we can change N = max( a, b ) 2: Decrease the value of N by 1. Determine the minimum number of moves required to reduce the value of N to 0. Input Format The first line contains the integer Q.

View Solution →## Truck Tour

Suppose there is a circle. There are N petrol pumps on that circle. Petrol pumps are numbered 0 to (N-1) (both inclusive). You have two pieces of information corresponding to each of the petrol pump: (1) the amount of petrol that particular petrol pump will give, and (2) the distance from that petrol pump to the next petrol pump. Initially, you have a tank of infinite capacity carrying no petr

View Solution →## Queries with Fixed Length

Consider an -integer sequence, . We perform a query on by using an integer, , to calculate the result of the following expression: In other words, if we let , then you need to calculate . Given and queries, return a list of answers to each query. Example The first query uses all of the subarrays of length : . The maxima of the subarrays are . The minimum of these is . The secon

View Solution →## QHEAP1

This question is designed to help you get a better understanding of basic heap operations. You will be given queries of types: " 1 v " - Add an element to the heap. " 2 v " - Delete the element from the heap. "3" - Print the minimum of all the elements in the heap. NOTE: It is guaranteed that the element to be deleted will be there in the heap. Also, at any instant, only distinct element

View Solution →## Jesse and Cookies

Jesse loves cookies. He wants the sweetness of all his cookies to be greater than value K. To do this, Jesse repeatedly mixes two cookies with the least sweetness. He creates a special combined cookie with: sweetness Least sweet cookie 2nd least sweet cookie). He repeats this procedure until all the cookies in his collection have a sweetness > = K. You are given Jesse's cookies. Print t

View Solution →## Find the Running Median

The median of a set of integers is the midpoint value of the data set for which an equal number of integers are less than and greater than the value. To find the median, you must first sort your set of integers in non-decreasing order, then: If your set contains an odd number of elements, the median is the middle element of the sorted sample. In the sorted set { 1, 2, 3 } , 2 is the median.

View Solution →