young tableaus

Young tableaus  这是 Introduction_to_algorithms一个 路学校运动, 我也难倒,互联网没有找到现有的应答。 今天 python 代码贴,供你参考。

#! /usr/bin/python

""" young tableau

m x n matrix

"""

import sys

class element():

def __init__(self, x, y):

self.x = x

self.y = y

def min_youngtableau(arry, p, m, n):

minimum = element(p.x, p.y)

if p.y < n and arry[p.x-1][p.y+1-1] < arry[p.x-1][p.y-1]:

minimum.y = p.y + 1

if p.x < m and arry[p.x+1-1][p.y-1] < arry[minimum.x-1][minimum.y-1]:

minimum.x = p.x + 1

minimum.y = p.y

if minimum.x != p.x or minimum.y != p.y:

temp = arry[p.x-1][p.y-1]

arry[p.x-1][p.y-1] = arry[minimum.x-1][minimum.y-1]

arry[minimum.x-1][minimum.y-1] = temp

p = element(minimum.x, minimum.y)

min_youngtableau(arry, p, m, n)

def extract_min(arry, m, n):

temp = arry[1-1][1-1]

arry[1-1][1-1] = 0xffff

p = element(1,1)

min_youngtableau(arry, p, m, n)

return temp

def inseart(arry, v, m, n):

if arry[m-1][n-1] != 0xffff:

print "arrary is full"

return

arry[m-1][n-1] = v

p = element(m, n)

while p.x > 1 or p.y > 1:

maxmum = element(p.x, p.y)

if p.x > 1 and arry[p.x-1-1][p.y-1] > arry[p.x-1][p.y-1]:

maxmum.x = p.x - 1

if p.y > 1  and arry[p.x-1][p.y-1-1] > arry[maxmum.x-1][maxmum.y-1]:

maxmum.x = p.x

maxmum.y = p.y-1

if maxmum.x == p.x and maxmum.y == p.y:

break

temp = arry[p.x-1][p.y-1]

arry[p.x-1][p.y-1] = arry[maxmum.x-1][maxmum.y-1]

arry[maxmum.x-1][maxmum.y-1] = temp

p = element(maxmum.x, maxmum.y)

def build_youngtaleau(arry, m, n):

arry2 = [

[0xffff, 0xffff, 0xffff],

[0xffff, 0xffff, 0xffff],

[0xffff, 0xffff, 0xffff],

[0xffff, 0xffff, 0xffff],

]

for i in range(m):

for j in range(n):

if arry[i][j] != 0xffff:

inseart(arry2, arry[i][j], m, n)

return arry2

def youngtableau_sort(arry, m, n):

arry = build_youngtaleau(arry, m, n)

result = []

for i in range(m):

for j in range(n):

result.append(extract_min(arry, m, n))

print result

if __name__ == ‘__main__‘:

arry = [

[12, 45, 50],

[34, 54, 13],

[77, 88, 99],

[87, 0xffff, 0xffff],

]

youngtableau_sort(arry, 4, 3)

版权声明:本文博客原创文章。博客,未经同意,不得转载。

时间: 2024-10-16 08:03:31

young tableaus的相关文章

Young Maids

E - Young Maids Time limit : 2sec / Memory limit : 256MB Score : 800 points Problem Statement Let N be a positive even number. We have a permutation of (1,2,…,N), p=(p1,p2,…,pN). Snuke is constructing another permutation of (1,2,…,N), q, following th

[2016-03-22][CF][69A][Young Physicist]

时间:2016-03-22 19:41:34 星期二 题目编号:[2016-03-22][CF][69A][Young Physicist] 题目大意:判断向量和是否为0 分析:对应坐标相加 遇到的问题:不能用x+y+z来判断是否都为0,除非输入都是正数 #include <cstdio> using namespace std; int main(){ int a,b,c,x,y,z,n; x = y = z = 0; scanf("%d",&n); for(in

线性DP POJ2279 Mr.Young&#39;s Picture Permutations

Mr. Young's Picture Permutations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1128   Accepted: 562 Description Mr. Young wishes to take a picture of his class. The students will stand in rows with each row no longer than the row behin

算法导论 6-3 Young氏矩阵

一.题目 二.思考 最小Young氏矩阵和最小堆的思想差不多,可以通过比较两者的同异来理解Young氏矩阵 不同点:   min-Heap min-Young 堆顶(最小值) H[1] Y[i][j] 最后一个元素的位置 H[N] Y[N][N] 最后一个元素 不一定是最大值 一定是最大值 parent H[i]的parent是H[i/2] Y[i][j]的parent是Y[i-1][j]和Y[i][j-1] child H[i]的child是H[i*2]和H[i*2+1] Y[i][j]的ch

Young Table(暴力,交换位置)

Young Table Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 237B Appoint description:  System Crawler  (2016-04-26) Description You've got table a, consisting of n rows, numbered from 1

p,将Young 区升级为Older区Older区的大小等

第一个线程负责回收Heap的Young区第二个线程在Heap不足时,遍历Heap,将Young 区升级为Older区Older区的大小等于-Xmx减去-Xmn,不能将-Xms的值设的过大,因为第二个线程被迫运行会降低JVM的性能. JVM的垃圾回收机制详解和调优1.JVM的gc概述 gc即垃圾收集机制是指jvm用于释放那些不再使用的对象所占用的内存.java语言并不要求jvm有gc,也没有规定gc如何工作.不过常用的jvm都有gc,而且大多数gc都使用类似的算法管理内存和执行收集操作. 在充分理

Forever Young

Let's dance in style 让我们翩然起舞 Let's dance for a while 让我们尽情欢笑 Heaven can wait 天堂也得等著我们 We're only watching the skies 我们只是仰望凝视著天空 Hoping for the best 愿望有最好的结果 But expecting the worst 却作了最坏的打算 Are you going to drop the bomb or not 你到底是否即将要投下炸弹 Let us di

Always young

原文 My aunt Jennifer is an actress. She must be at least thirty-five years old. In spite of this, she often appears on the stage as a young girl. Jennifer will have to take part in a new play soon. This time, she will be a girl of seventeen. In the pl

The Sorrows of Young Werther

The Sorrows of Young Werther J.W. von Goethe Thomas Carlyle and R.D. Boylan Edited by Nathen HaskellDole PREFACE I have carefully collected whatever I have been able to learnof the story of poor Werther, and here present it to you , knowing thatyou w