# 计算几何初探## 题目描述本题是代码填空题按要求补充给出代码的空白即可通过题目。c++#includebitsstdc++husing namespace std;const int N = 205;int n m;struct Point int x y; double det return sqrtdoublex x + y y; Point o
#include<bits/stdc++.h>
using namespace std;
const int N = 205;
int n, m;
struct Point{
int x, y;
double det(){
return sqrt((double)x * x + y * y);
}
Point operator+(const Point& p){
Point res;
res.x = x + p.x;
res.y = y + p.y;
return res;
}
} p[N];
Point operator-(const Point& a, const Point& b){
Point res;
res.x = a.x - b.x;
res.y = a.y - b.y;
return res;
}
int dot(const Point& a, const Point& b){
return a.x * b.x + a.y * b.y;
}
int cross(const Point& a, const Point& b){
return a.x * b.y - a.y * b.x;
}
double dis(const Point& a, const Point& b){
int dx = a.x - b.x;
int dy = a.y - b.y;
return sqrt(dx * dx + dy * dy);
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i)
scanf("%d%d", &p[i].x, &p[i].y);
for(int i = 1; i <= m; ++i){
int op, r, s;
scanf("%d%d", &op, &r);
if(op != 1)
scanf("%d", &s);
if(op == 1){
printf("%.2lf\n", p[r].det());
}
else if(op == 2){
Point t = p[r] + p[s];
printf("%d %d\n", t.x, t.y);
}
else if(op == 3){
Point t = p[r] - p[s];
printf("%d %d\n", t.x, t.y);
}
else if(op == 4){
printf("%d\n", dot(p[r], p[s]));
}
else if(op == 5){
printf("%d\n", cross(p[r], p[s]));
}
else if(op == 6){
printf("%.2lf\n", dis(p[r], p[s]));
}
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/ibjW 著作权归作者所有。请勿转载和采集!