Advertisement
Guest User

GCJ QR 2016 Fractiles D Large

a guest
Apr 10th, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import sys, copy;
  2.  
  3. def solve():
  4.     #print(k,c,s)
  5.     if k == s:
  6.         return ' '.join(str(x+1)for x in range(k))
  7.     if s * c < k:
  8.         return 'IMPOSSIBLE'
  9.     tile = 1
  10.     res = []
  11.     for i in range(0, s):
  12.         position = 0
  13.         #print('i:', i, ' pos:', position)
  14.         for j in range(0, c):
  15.             #print('j:', j, ' pos:', position)
  16.             position *= k
  17.             position += tile - 1
  18.             tile+=1
  19.             if tile>k:
  20.                 tile=1
  21.         #print('i:', i, ' pos:', position)
  22.         res.append(position)
  23.     return ' '.join(str(x+1)for x in res);
  24.  
  25. inputFile =  sys.argv[1] if (len(sys.argv) > 1) else "input.txt";
  26. outputFile = sys.argv[2] if (len(sys.argv) > 2) else (inputFile + "out.txt") if (len(sys.argv) > 1) else "output.txt";
  27. print( inputFile, outputFile)
  28. file = open(outputFile, "w")
  29.  
  30. with open(inputFile, 'r') as f:
  31.     t = int(f.readline())
  32.     #print(t)
  33.     for i in range(1, t + 1):
  34.         file.write("Case #" + str(i) + ": ")
  35.         k,c,s = map(int, f.readline().split())
  36.         #print(k,c,s)
  37.         x = solve()
  38.         #print(x)
  39.         file.write(str(x) + "\n")
  40. file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement