注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
看来IMC今年出的题都是一样,地里原题,有点后悔没看
1. Is there a path
2.Busy intersection
我只写出来第一道题第二道题大概思路有了但没写完
第一题的code,全部test case passed,基本是改的:
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'canReach' function below.
#
# The function is expected to return a STRING.
# The function accepts following parameters:
# 1. INTEGER c
# 2. INTEGER x1
# 3. INTEGER y1
# 4. INTEGER x2
# 5. INTEGER y2
#
def canReach(c, x1, y1, x2, y2):
# Write your code here
'''
x1, x2 start
x2, y2 end
'''
dict = []
#print(isPerfectSquare(2, 6))
if isPerfectSquare(x2, y2):
return 'No'
if 'Yes' in dict:
return 'Yeerfect square, need to check the sqrt as integer
#print(math.sqrt(x + y))
if x + y < 0:
return True
return (int(math.sqrt(x + y)) ** 2) == (x + y)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
c = int(input().strip())
x1 = int(input().strip())
y1 = int(input().strip())
x2 = int(input().strip())
y2 = int(input().strip())
result = canReach(c, x1, y1, x2, y2)
fptr.write(result + '\n')
fptr.close() |