示例#1
0
def main(argv):
    if len(argv) != 2:
        sys.stderr.write('usage: %s result_file\n' % argv[0])
        return 1

    classes = []
    with open(argv[1], 'r') as f:

        perm = f.readline().strip().split()
        assert len(perm) == 2 and perm[0] == 'perm'
        perm = Permutation(map(int, perm[1]), check=True)

        length = f.readline().strip().split()
        assert len(length) == 2 and length[0] == 'length'
        length = int(length[1])

        mp_cnt = 2**((len(perm) + 1) ** 2)
        uf = UnionFind(mp_cnt)
        assert f.readline().strip() == 'union find'
        for x, p in enumerate(map(int, f.readline().strip().split())):
            uf.unite(x, p)

        assert f.readline().strip() == 'classes'
        while True:
            cls = f.readline()
            if cls == '':
                break
            cls = map(int, cls.strip().split())
            classes.append(cls)

    global outfile
    outfile = 'surprising_%s.txt' % ''.join(map(str, perm))
    log('Writing output to %s' % outfile)
    outfile = open(outfile, 'w')

    outfile.write('perm %s\n' % ''.join(map(str, perm)))
    outfile.write('length %s\n' % length)

    params = []
    params.append((-1,False,False,0)) # Dummy params for shading lemma

    for depth in range(1, 9+1):
        for multbox in [False,True]:
            for q_check in [False,True]:
                for force_len in range(1, len(perm)+1):
                    params.append((depth, multbox, q_check, force_len))

    for par in params:
        classes = classify(classes, perm, mp_cnt, uf, *par)

    outfile.close()
    return 0
示例#2
0
    line = f.readline()
    if not line:
        if expect is not None:
            assert False
        return None, None
    key, val = line.strip().split(' ', 1)
    if expect is not None:
        assert expect == key
        return val
    return key, val


perm = get('perm')
n = len(perm)
length = int(get('length'))
uf = UnionFind(2**((n+1)**2))
surprising = []
params = []

while True:
    key,val = get()
    if not key:
        break
    if key == 'params':
        surprising = []
        params.append([eval(val), 0])
    elif key == 'unite':
        params[-1][1] += 1
        a,b = map(int,val.split())
        uf.unite(a,b)
    elif key == 'surprising':