摘要: pygame是用来写2D游戏的。实现斜线运动,无非是在x和y两个方向上分运动的合成。x方向上的运动,当撞到边界的时候取相反速度就好了。这里是用网球王子中的图片,以及一个网球实现,效果截图:注意看,那个方块形状的网球是会动的,撞到边界就反弹,时刻匀速(这情况太理想了。。。)代码:# coding:utf-8bgimg = 'teni.jpg'spimg = 'ball.jpg'import pygamefrom pygame.locals import *from sys import exitpygame.init()screen = pygame.displa 阅读全文
posted @ 2013-08-17 13:45 ChrisZZ 阅读(887) 评论(0) 推荐(0) 编辑
摘要: 用hash解决。我python代码消耗很多内存,好在代码比C++短很多n = int(raw_input())mylist = raw_input().split(' ')i = 0zid = {}for x in mylist: zid[x] = i i += 1q = int(raw_input())m = raw_input().split(' ')ans1 = 0ans2 = 0for y in m: tmp = zid[y] ans1 += tmp + 1 ans2 += n - tmpprint ans1, ans2 阅读全文
posted @ 2013-08-17 01:39 ChrisZZ 阅读(252) 评论(0) 推荐(0) 编辑
摘要: codeforces题目,用python写本题输入三个点坐标,考察叉积,若大于0则right,小于0则left,等于0则towards代码:a = raw_input().split()b = raw_input().split()c = raw_input().split()xa = int(a[0])ya = int(a[1])xb = int(b[0])yb = int(b[1])xc = int(c[0])yc = int(c[1])x1 = xb - xax2 = xb - xcy1 = yb - yay2 = yb - ycres = x1 * y2 - x2 * y1if res 阅读全文
posted @ 2013-08-17 00:35 ChrisZZ 阅读(369) 评论(0) 推荐(0) 编辑