Simulation.
n = int(raw_input())
g = [[1 for i in xrange(n)] for j in xrange(n)]
for i in xrange(1, n):
for j in xrange(1, n):
g[i][j] = g[i - 1][j] + g[i][j - 1]
print g[n - 1][n - 1]
Brute force.
There are multiple ways to form a 2*2 square at one single step.
So at every step, we have to check the neighbours of pixel that is colored black.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define …
There are a lot of interview problem based on the 1D-array, which is the one of the easiest "data structure".
But the problem about that simple data structure might not be that simple. Here is the summary of the problem about 1D-array.
Of course, most of them come from …
more ...Trun x => X
or X => x
to make the number of 'x' is equal to the number of 'X'.
n = int(raw_input())
hamsters = [c for c in raw_input()]
sits = hamsters.count('x')
stands = hamsters.count('X')
if sits == stands:
print 0
print ''.join(hamsters)
else:
if sits > stands …
It has been months that I didn't participate in the contest on CF, now I'm back. :)
This round of contest makes me confused that the problem B and C is a little bit too twisted, if you can't catch the vital point, you will get a lot of WAs …
more ...水题,杠杆原理。
用^
把字符串分割开。然后分别计算两边的重量即可。
#Result: Dec 24, 2013 6:04:41 PM Wizmann A - Lever Python 2 Accepted 312 ms 4200 KB
def calc(ss …