洛谷P5735 【深基7.例1】距離函數(shù)題解
原題鏈接:https://www.luogu.com.cn/problem/P5735
我的洛谷:https://www.luogu.com.cn/user/453321
金色傳說!
我從來沒有見過如此良心之題目
把算法公式直接白給的

那有的小伙伴就要問了
啊啊啊啊這個"√"該怎么打啊
不用慌
現(xiàn)在不像以前那樣需要自己打了(敬畏以前那些靠手打根號的程序猿)
只需要 cmath(math.h)這個頭文件和sqrt() 就能搞定
s所以我們可以求出這個公式:
sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))+sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3))+sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3))
然后上代碼:
#include<bits/stdc++.h>?
using namespace std; int main(){ ?
float x1,x2,x3,y1,y2,y3; ?
cin>>x1>>y1>>x2>>y2>>x3>>y3;?
?printf("%.2f",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))+sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3))+sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)));?
}
本文章為我自己原創(chuàng)作品,可供學(xué)習(xí)使用,嚴禁抄襲,復(fù)制。抄襲必究
標簽: