Python解决codeforces ---- 5
来源:互联网 发布:做淘宝客服能学到什么 编辑:程序博客网 时间:2024/06/04 19:47
第一题 13A
题意:给定一个数n,求2~(n-1)进制的所有数的位数总和/n-2,输出的格式应该是最简
思路:直接暴力求解
代码:
#!/bin/pythonn = int(raw_input())# getAnsdef gcd(a , b): if b == 0: return a return gcd(b , a%b)sum = 0i = 2while i < n: tmp = n while tmp: sum += tmp%i tmp /= i i += 1# outputprint "%d/%d" % (sum/gcd(sum,n-2) , (n-2)/gcd(sum,n-2))
第二题 14A
题意:给定一个n*m的矩形,矩形的每一个元素是*或者.,由于这个矩形可能会有很多的没用的.,因此要求把这个矩形话到最简
思路:直接求出左上角和又上角,然后输出即可
代码:
#!/bin/python# inputn,m = map(int , raw_input().split())mat = []for i in range(n): mat.append(raw_input())# getx1def getx1(): for i in range(n): for j in range(m): if mat[i][j] == '*': return i# gety1def gety1(): for i in range(m): for j in range(n): if mat[j][i] == '*': return i# getx2def getx2(): i = n-1 while i >= 0: j = m-1 while j >= 0: if mat[i][j] == '*': return i j -= 1 i -= 1# gety2 def gety2(): j = m-1 while j >= 0: i = n-1 while i >= 0: if mat[i][j] == '*': return j i -= 1 j -= 1# outputx1 = getx1()x2 = getx2()y1 = gety1()y2 = gety2()for i in range(x1,x2+1): print mat[i][y1:y2+1]
第三题 15A
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the Оx-axis, to be square in shape, have a side t, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the Ox-axis and it shouldn't overlap any of the houses in the village.
Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house?
The first line of the input data contains numbers n and t (1 ≤ n, t ≤ 1000). Then there follow n lines, each of them contains two space-separated integer numbers: xi ai, where xi — x-coordinate of the centre of the i-th house, and ai — length of its side ( - 1000 ≤ xi ≤ 1000, 1 ≤ ai ≤ 1000).
Output the amount of possible positions of the new house.
2 20 46 2
4
2 20 45 2
3
2 30 45 2
2
It is possible for the x-coordinate of the new house to have non-integer value.
题意:有一个人想要建房子,这些房子都是建在x轴上面的,现在已经有n个房子是建好的。给定新建的房子的长为t,问总共能在几个位置建新房子
思路:利用字典保存n个已经建好的房子的位置,然后枚举一遍即可
代码:
# inputn,t = map(int , raw_input().split())dict = {}for i in range(n): x,a = map(int , raw_input().split()) dict[x] = a# getAnsans = 2list = dict.keys()list.sort()pre = -(1<<30)for key in list: a = float(dict[key])/2 if pre != -(1<<30): dis = abs((key-a)-pre) if dis > t: ans += 2 elif dis == t: ans += 1 pre = key+a# outputprint ans
- Python解决codeforces ---- 5
- Python解决codeforces ---- 1
- Python解决codeforces ---- 2
- Python解决codeforces ---- 3
- Python解决codeforces ---- 4
- Python解决codeforces ---- 6
- Python解决codeforces ---- 7
- paip.python错误解决5
- codeforces python / pike solutions
- codeforces 570A【python】
- codeforces 719A 【python】
- codeforces 731A【python】
- codeforces 151A【python】
- codeforces 560A【python】
- codeforces 651A python
- Review of Codeforces 5A and 5B(Python)
- python codeforces 322 div2 C
- Python解决打靶问题
- ps命令复习
- linux文件与目录管理
- CUDA, 用于大量数据的超级运算:第三节
- 使用lsusb命令查看系统中的USB设备
- 使用TabHost实现卡片选项菜单实例
- Python解决codeforces ---- 5
- Windows SDK 7.1及DirectShow安装教程
- weblogic、cxf、axis2等札记
- Weblogic内存分配
- 博客开通了
- epoll
- Android 分享文本和图片
- 使用TabHost实现微博客户端界面
- H.264视频的RTP荷载格式