結果

問題 No.760 Where am I moved to?
ユーザー cielciel
提出日時 2018-11-27 08:40:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,519 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,844 KB
実行使用メモリ 59,264 KB
最終ジャッジ日時 2023-09-09 05:51:52
合計ジャッジ時間 6,144 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
56,988 KB
testcase_01 AC 384 ms
58,056 KB
testcase_02 AC 312 ms
58,068 KB
testcase_03 WA -
testcase_04 AC 300 ms
58,152 KB
testcase_05 WA -
testcase_06 AC 297 ms
58,048 KB
testcase_07 AC 298 ms
58,092 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
from numpy import array,linalg
from scipy import optimize
import sys,math

def thirdPoint(a):
	xdiff=a[1][0]-a[0][0]
	ydiff=a[1][1]-a[0][1]
	return [a[1][0]-ydiff,a[1][1]+xdiff]

#Least squares method with scipy.optimize
def fit_func(orig_parameter):
	def f(parameter, xdata, ydata):
		# ydata = final * interminv * xdata
		old_theta = orig_parameter[2]*math.pi/180
		a = parameter[0]
		b = parameter[1]
		new_theta = parameter[2]*math.pi/180
		# transform x
		intermidiate = array([[math.cos(old_theta),-math.sin(old_theta),orig_parameter[0]],[math.sin(old_theta),math.cos(old_theta),orig_parameter[1]],[0,0,1]])
		final = array([[math.cos(new_theta),-math.sin(new_theta),a],[math.sin(new_theta),math.cos(new_theta),b],[0,0,1]])
		res = []
		resultdata = []
		for (x,y) in zip(xdata,ydata):
			r = intermidiate.dot(linalg.inv(final).dot([x[0],x[1],1]))
			resultdata.append((r[0],r[1]))
			res.append(math.hypot(y[0]-r[0],y[1]-r[1]))
		return res
	return f

N=2
orig_parameter = list(map(float,sys.stdin.readline().split()))
xdata = [list(map(float,sys.stdin.readline().split())) for _ in range(N)]
ydata = [list(map(float,sys.stdin.readline().split())) for _ in range(N)]

result0 = optimize.leastsq(fit_func(orig_parameter),orig_parameter,args=(xdata+[thirdPoint(xdata)],ydata+[thirdPoint(ydata)]))
result = optimize.least_squares(fit_func(orig_parameter),result0[0],args=(xdata+[thirdPoint(xdata)],ydata+[thirdPoint(ydata)]),method='trf')
print(' '.join('%.12f'%e for e in result.x))
print(result)
0