Created
January 20, 2014 18:40
-
-
Save cocodrips/8526317 to your computer and use it in GitHub Desktop.
CodeForces 225 Div2 B問題
テストケース3で落ちるー(´;ω;`)
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
| class Solve: | |
| ans = [] | |
| def __init__(self,n,m,k,data): | |
| self.n = n | |
| self.m = m | |
| if k == 1: | |
| data = [[dd * -1 for dd in d] for d in data] | |
| for g in xrange(self.n): | |
| self.quickSort(data, g, 0, self.m-1) | |
| print len(self.ans) | |
| if k == 1: | |
| for a in self.ans: | |
| print ' '.join(a[::-1]) | |
| else: | |
| for a in self.ans: | |
| print ' '.join(a) | |
| def quickSort(self, data, i, left, right): | |
| index = self.partition(data, i, left, right) | |
| if left < index - 1: | |
| self.quickSort(data, i, left, index-1) | |
| if index < right: | |
| self.quickSort(data, i ,index, right) | |
| def partition(self, data, i, left, right): | |
| pivot = data[i][(left + right)/2] | |
| while left < right: | |
| while data[i][left] < pivot: | |
| left +=1 | |
| while data[i][right] > pivot: | |
| right -=1 | |
| if left < right and data[i][left] > data[i][right]: | |
| self.ans.append([str(left+1), str(right+1)]) | |
| for o in xrange(self.n): | |
| if data[o][left] > data[o][right]: | |
| tmp = data[o][left] | |
| data[o][left] = data[o][right] | |
| data[o][right] = tmp | |
| left += 1 | |
| right -= 1 | |
| return left | |
| if __name__ == "__main__": | |
| n, m, k = map(int, raw_input().split()) | |
| data = [] | |
| for _ in xrange(n): | |
| data.append(map(int, raw_input().split())) | |
| Solve(n, m, k, data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment