Created
October 22, 2011 17:01
-
-
Save whs/1306217 to your computer and use it in GitHub Desktop.
COCI 2011/2012
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def getInput(): | |
| l1 = raw_input() | |
| l1 = map(lambda x: int(x), l1.split(" ")) | |
| fallpos = [] | |
| for i in range(input()): | |
| fallpos.append(input()) | |
| return { | |
| "width": l1[1], | |
| "size": l1[0], | |
| "apples": fallpos | |
| } | |
| def weCanCatch(apple,pos): | |
| global inp | |
| return apple >= pos and apple <= pos + inp['width'] | |
| inp = getInput() | |
| # Turn simulator FTW! | |
| turn = 1 | |
| thisApple=None | |
| nextApple=None | |
| pos = 0 | |
| while True: | |
| if not thisApple: | |
| try: | |
| thisApple = inp['apples'].pop(0) | |
| except IndexError: | |
| break | |
| try: | |
| nextApple = inp['apples'][0] | |
| except IndexError: | |
| nextApple = None | |
| if weCanCatch(thisApple, pos): | |
| #print "Catching! "+`thisApple` | |
| thisApple = None | |
| else: | |
| if thisApple > pos: | |
| pos += 1 | |
| #print "Right "+`pos` | |
| else: | |
| pos -= 1 | |
| #print "Left "+`pos` | |
| turn += 1 | |
| print turn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| matrix = [] | |
| size = input() | |
| for l in range(size): | |
| matrix.append(map(lambda x: int(x), raw_input().split(" "))) | |
| def beautiful(m): | |
| out = 0 | |
| for i in range(len(m)): | |
| out += m[i][i] | |
| for i in range(len(m)): | |
| out -= m[i][len(m)-1-i] | |
| return out | |
| bdata = [] | |
| for s in range(2, size+1): | |
| for w in range(size-1): | |
| for h in range(size-1): | |
| thisMatrix = [] | |
| if h+s > size: continue | |
| if w+s > size: continue | |
| #print h+s, w, h, s | |
| for i in range(h, h+s): | |
| thisMatrix.append(matrix[i][w:w+s]) | |
| #print thisMatrix | |
| bdata.append(beautiful(thisMatrix)) | |
| #print beautiful(thisMatrix) | |
| print max(bdata) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| raw_input() | |
| boys = map(lambda x: int(x), raw_input().split(" ")) | |
| girls = map(lambda x: int(x), raw_input().split(" ")) | |
| boys = sorted(boys, key=lambda x:abs(x)) | |
| girls = sorted(girls, key=lambda x:abs(x)) | |
| #print boys | |
| out=0 | |
| for i in boys: | |
| h = abs(i) | |
| for k,v in enumerate(girls): | |
| if i < 0 and abs(v) < h: | |
| if abs(v) < h and v < 0: | |
| continue | |
| elif abs(v) > h and v > 0: | |
| continue | |
| #print i, v | |
| girls.pop(k) | |
| out+=1 | |
| elif i > 0 and abs(v) > h: | |
| if abs(v) < h and v < 0: | |
| continue | |
| elif abs(v) > h and v > 0: | |
| continue | |
| #print i, v | |
| girls.pop(k) | |
| out+=1 | |
| print out |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| raw_input() | |
| l = map(lambda x:int(x), raw_input().split(" ")) | |
| o=0 | |
| while l != range(1, len(l)+1): | |
| # partitions | |
| parts = [] | |
| curPart = [] | |
| for k,v in enumerate(l): | |
| if k == len(l)-1: | |
| curPart.append(v) | |
| parts.append(curPart) | |
| break | |
| if v > l[k+1]: | |
| curPart.append(v) | |
| else: | |
| curPart.append(v) | |
| parts.append(curPart) | |
| curPart = [] | |
| for k,v in enumerate(parts): | |
| if len(v) <= 1: continue | |
| parts[k] = v[::-1] | |
| o+=1 | |
| # flatten | |
| l = [] | |
| for i in parts: | |
| for x in i: | |
| l.append(x) | |
| #print l | |
| print o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| print "1000000" | |
| for i in range(1000000): | |
| print random.randrange(1,1000000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import operator, itertools | |
| inp = [] | |
| out = 0 | |
| for i in range(input()): | |
| inp.append(input()) | |
| for i in itertools.combinations(inp, 2): | |
| #print i | |
| out += operator.xor(i[0], i[1]) | |
| print out |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Jabuke
All but one test case are incorrect
Matrix
Three test cases are correct, the rest were exceeding time limit.
X3
All test cases were returning non-zero exit code for unknown reason
Ples
Some subtest are incorrect, thus rendering entire testcase incorrect. From testcase 5, the time limit are exceeded.
Sort
Only two test cases are correct. The rest were exceeding time limit.