实验吧编程WP(一)

来源:互联网 发布:泰拉瑞亚mac版汉化 编辑:程序博客网 时间:2024/06/07 05:43

1.生日蜡烛(http://www.shiyanbar.com/ctf/1933)
根据题目要求跑个python或者手算也行
这里写图片描述

2.奖券(http://www.shiyanbar.com/ctf/1932)
还是跑python
这里写图片描述

3.三羊献瑞(http://www.shiyanbar.com/ctf/1924)
PPC题型就是这样,还是python

def check(n):        s = str(n)        a=[s.count(str(i)) for i in s]        for i in a:                if i >=2:                        return False                else :pass        return Truefor n1 in range(8000,9999):        if check(n1):                for n2 in range(1000,1999):                        if check(n2) and str(n2)[3]==str(n1)[1]:                                sum =n1+n2                                if len(str(sum))==5 and check(sum) and check(str(n1)+str(n2)[0:3]+str(sum)[4]) and str(sum)[0:2]==str(n2)[0:2] and str(sum)[2]==str(n1)[2] and str(sum)[3]==str(n1)[1]:                                        print 'CTF{%s}' %  (n2) 

4.找素数(http://www.shiyanbar.com/ctf/1922)
PYTHON:

def judge(n):                 m=range(2,int(n/2+1))    for i in m:        if n%i==0:            return 0    return 1          num=367count=0while True:    n=judge(num)    if n==1:        count+=1    if count==151:        break    num+=186print(num)

5.循环(http://www.shiyanbar.com/ctf/1921)

def judge(n):    if n%2==0:        return 0    else :        return 1def cal(n):    if judge(n)==0:        n=n/2    elif judge(n)==1:        n=3*n+1    return nnum=range(900,1001)count=0max=0for n in num:    count=0    while True:        n=cal(n)        count+=1        if n==1:            break        else :            n=cal(n)            count+=1    if count>max:        max=countmax+=1print(max)

6.迷宫大逃亡(http://www.shiyanbar.com/ctf/1934)
这题算法的关系还要跑几分钟

def indexes(x, y, n):    return x * n + ydef isin(x, y, n):    if x < 0 or x >= n:        return 0    if y < 0 or y >= n:        return 0    return 1def seek2(x, y, n, maze, accessible):    accessible[indexes(x, y, n)] = 'O'    for num in xrange(n):        for cd_x in xrange(0, n):            for cd_y in xrange(0, n):                if accessible[indexes(cd_x, cd_y, n)] == 'O':                    if isin(cd_x + 1, cd_y, n):                        if maze[indexes(cd_x + 1, cd_y, n)] == 'O':                            accessible[indexes(cd_x + 1, cd_y, n)] = 'O'                    if isin(cd_x - 1, cd_y, n):                        if maze[indexes(cd_x - 1, cd_y, n)] == 'O':                            accessible[indexes(cd_x - 1, cd_y, n)] = 'O'                    if isin(cd_x, cd_y + 1, n):                        if maze[indexes(cd_x, cd_y + 1, n)] == 'O':                            accessible[indexes(cd_x, cd_y + 1, n)] = 'O'                    if isin(cd_x, cd_y - 1, n):                        if maze[indexes(cd_x, cd_y - 1, n)] == 'O':                            accessible[indexes(cd_x, cd_y - 1, n)] = 'O'filename = 'in.txt'filename = filename.decode('utf-8')fi = open(filename)ctf = ''T = int(fi.readline())for i in xrange(T):    print 'T= ', i    n = int(fi.readline())    incd = fi.readline().split(' ')    outcd = fi.readline().split(' ')    for j in xrange(2):        incd[j] = int(incd[j]) - 1        outcd[j] = int(outcd[j]) - 1    maze = []    accessible = []    line = ''    for x in xrange(n):        line = fi.readline()        for y in xrange(n):            maze.append(line[y])            accessible.append('X')    seek2(incd[0], incd[1], n, maze, accessible)    if accessible[indexes(outcd[0], outcd[1], n)] == 'O':        ctf += '1'    else:        ctf += '0'flag = ''for i in xrange(0, len(ctf), 8):    flag += chr(int(ctf[i:i + 8], 2))print flagprint flag.decode('base64')

这里写图片描述

7.小球下落(http://www.shiyanbar.com/ctf/1913)

a = [0 for x in range(65536)]for i in range(0,12345):    tmp=1    for x in range(0,15):        if(a[tmp]==0):            a[tmp]=~a[tmp]            tmp=tmp*2        else:            a[tmp]=~a[tmp]            tmp=tmp*2+1        if(i==12344):            print tmp 

8.求底运算(http://www.shiyanbar.com/ctf/1912)

for i in range(1, 1500):    p = i ** 7    if p == 4357186184021382204544:        print i        break
0 0
原创粉丝点击