Created
October 12, 2011 14:16
-
-
Save yasuharu519/1281335 to your computer and use it in GitHub Desktop.
GoogleCodeJamJapan2011 予選 問題A.カードシャッフル
This file contains 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def _test(): | |
import doctest | |
doctest.testmod() | |
def cut(cardList, fromA, toB): | |
""" | |
>>> a = [1] | |
>>> cut(a, 1, 1) | |
[1] | |
>>> a[0] | |
1 | |
>>> a = [1, 2] | |
>>> a = cut(a, 2, 1) | |
>>> a = cut(a, 2, 1) | |
>>> a = cut(a, 2, 1) | |
>>> a[0] | |
2 | |
""" | |
cutted = cardList[fromA-1:fromA-1 + toB] | |
cardList = cardList[:fromA-1] + cardList[fromA-1 + toB:] | |
return cutted + cardList | |
def readFile(FILENAME): | |
numOfTests = 0 | |
writefile = open("outputAlarge.txt", "w") | |
with open(FILENAME) as readfile: | |
numOfTests = int(readfile.readline()) | |
for i in range(numOfTests): | |
line = readfile.readline() | |
M, C, W = tuple([int(x) for x in line.split()]) | |
cardList = range(1, M + 1) | |
for times in range(C): | |
A, B = tuple([int(x) for x in readfile.readline().split()]) | |
cardList = cut(cardList, A, B) | |
writefile.write("Case #" + str(i + 1) + ": " + | |
str(cardList[W-1]) + "\n") | |
print "case #" + str(i + 1) + " is done" | |
writefile.close() | |
if __name__ == "__main__": | |
FILENAME = "./A-large.in" | |
readFile(FILENAME) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment