結果

問題 No.760 Where am I moved to?
ユーザー cielciel
提出日時 2018-11-26 23:20:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,365 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 94,792 KB
最終ジャッジ日時 2023-09-09 05:51:43
合計ジャッジ時間 8,373 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
57,988 KB
testcase_01 AC 298 ms
57,976 KB
testcase_02 AC 294 ms
57,968 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 297 ms
57,112 KB
testcase_07 WA -
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)]

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