forked from anubhab91/CodeForces-5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoder.py
More file actions
74 lines (64 loc) · 1.35 KB
/
Coder.py
File metadata and controls
74 lines (64 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
__author__ = 'Devesh Bajpai'
'''
http://codeforces.com/problemset/problem/384/A
Algorithm: Seggregate the input into 2 cases: n being odd or not. Follow the code for 2 cases.
'''
# build the grid when n is even
def evenGrid(n):
result = list()
cur1 = ""
cur2 = ""
for i in range(0,n,2):
cur1+="C."
for i in range(0,n,2):
cur2+=".C"
for i in range(0,n,2):
result.append(cur1)
result.append(cur2)
return result
# build the grid when n is odd
def oddGrid(n):
result = list()
cur1 = ""
cur2 = ""
for i in range(0,n,2):
cur1+="C."
cur1 = cur1[:-1]
for i in range(0,n,2):
cur2+=".C"
cur2 = cur2[:-1]
for i in range(0,n,2):
result.append(cur1)
result.append(cur2)
del result[-1]
return result
# calculate the total pieces based on n being odd or not
def solve(n):
result = ()
if(n%2==0):
result = evenGrid(n)
print (n/2) * n
else:
result = oddGrid(n)
print ((n/2)+1)*((n/2)+1) + (n/2)*(n/2)
for i in range(0,len(result)):
print result[i]
if __name__ == "__main__":
n = int(raw_input())
solve(n)
#reference grids
'''
CASE 1: n is even (4)
c.c.
.c.c
c.c.
.c.c
'''
'''
CASE 2: n is odd (5)
c.c.c
.c.c.
c.c.c
.c.c.
c.c.c
'''