第一题 13A
题意:给定一个数n,求2~(n-1)进制的所有数的位数总和/n-2,输出的格式应该是最简
思路:直接暴力求解
代码:
#!/bin/python
n = int(raw_input())
# getAns
def gcd(a , b):
if b == 0:
return a
return gcd(b , a%b)
sum = 0
i = 2
while i < n:
tmp = n
while tmp:
sum += tmp%i
tmp /= i
i += 1
# output
print "%d/%d" % (sum/gcd(sum,n-2) , (n-2)/gcd(sum,n-2))
第二题 14A
题意:给定一个n*m的矩形,矩形的每一个元素是*或者.,由于这个矩形可能会有很多的没用的.,因此要求把这个矩形话到最简
思路:直接求出左上角和又上角,然后输出即可
代码:
#!/bin/python
# input
n,m = map(int , raw_input().split())
mat = []
for i in range(n):
mat.append(raw_input())
# getx1
def getx1():
for i in range(n):
for j in range(m):
if mat[i][j] == '*':
return i
# gety1
def gety1():
for i in range(m):
for j in range(n):
if mat[j][i] == '*':
return i
# getx2
def 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
# output
x1 = 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»nsquare 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 sidet, 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 theOx-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?
Output
Output the amount of possible positions of the new house.
Note
It is possible for thex-coordinate of the new house to have non-integer value.
题意:有一个人想要建房子,这些房子都是建在x轴上面的,现在已经有n个房子是建好的。给定新建的房子的长为t,问总共能在几个位置建新房子
思路:利用字典保存n个已经建好的房子的位置,然后枚举一遍即可
代码:
# input
n,t = map(int , raw_input().split())
dict = {}
for i in range(n):
x,a = map(int , raw_input().split())
dict[x] = a
# getAns
ans = 2
list = 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
# output
print ans
分享到:
相关推荐
在python和bash中使用简单的解析和检查实现,以解决Codeforce中的竞赛。\ 安装 git clone " https://github.com/siddharth17196/codeforces-cli.git " cd codeforces-cli/scripts bash install.sh 将以下内容添加...
Codeforces-Round-492-:解决问题shorturl.atetAIW
codeforces-scraper:刮除来自codeforces的解决方案
:exploding_head: :exploding_head: :female_sign: 我准备链接问题和解决方案 :person_raising_hand: :female_sign: 您已克隆并尝试以下操作:使用Python代码,必须先下载python然后再运行它 :star: :female_sign: ...
codeforces-crawler 一个建议问题,进行虚拟竞赛并为编码平台codeforce的用户显示用户统计信息的网站。 网站链接: 要求 安装要求 导航到目录并运行 点安装-r requirements.txt 运行项目 导航到目录并运行 python ...
CodeForces 适用于问题的Python解决方案。 用户名: hopper19
Codeforces解决方案
单击问题名称以访问Codeforces上的原始问题页面,进行解决,然后返回此处并重复。 祝你好运,高评价! 链接到已部署的应用程序 链接到Codeforces博客 注意 随时提出有关错误/改进的问题。 如果对存储库有任何帮助...
Codeforces解决方案该存储库包含我在codeforces.com上提交并接受的各种问题的解决方案。
Python竞争性编程解决方案 此仓库由My Python解决方案组成,用于解决LeetCode,HackerEarth,GeeksforGeeks,Codechef等各种问题。 解决方案将定期更新。
Codeforces问题解决方案
codeforces解决方案个人资料链接
5 月 30 日更新:我决定将 leetcode 解决方案留在 leetcode 本身。 当我在 IDE 上编码时,传输代码太麻烦了。 代码力量 还包括 Leet Code 问题 - 30 天挑战 我决定使用 c++ 因为 python 解决方案太慢了 编辑:坚持...
Codeforces_Problemset_Solution Codeforces问题的解决方案将在这里上传。 我将尝试使用C ++解决大多数问题。
cp工具 cp-tool是一个自动生成器,用于解决不同在线法官的问题。 它收集了在线法官解决的所有问题,并为... cp-tool -c init -j codeforces 您会被要求 处理 例如: shifat57 存储库名称(将根据存储库名称创建一个文
如果解决方案已经存在,则将不会合并。 遵循命名约定。 例如:107D。 问题的名称.cpp 我在编码时经常忘记的事情: 使用lambda在python3中排序: 假设x是一个元组,并且排序将取决于x [0],如果x [0]相等,则x [1]...
力编码器 无需打开网站即可解决 CodeForces Round 问题! 文档和使用方法即将推出
跟踪您的竞争对手一个命令行实用程序,可以在Spoj,Codechef,Codeforces等各种在线法官上跟踪您的竞争对手。 想要查看您在Codechef上的朋友状态,或想要解决竞争对手在SPOJ上遇到的所有问题。 尝试跟踪您的竞争对手...
这种工具可以自动从codeforces找到高质量的Python解决的任务。 我写这个工具是为了帮助我找到好的资源来提高我的 Python 技能。 cd codeforces python solution-finder.py (number of the contest, e.g. 988) ...
解决 CodeForces 问题