結果
問題 | No.132 点と平面との距離 |
ユーザー |
![]() |
提出日時 | 2015-09-27 17:29:12 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 37 ms / 5,000 ms |
コード長 | 2,461 bytes |
コンパイル時間 | 693 ms |
コンパイル使用メモリ | 88,844 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 10:52:31 |
合計ジャッジ時間 | 1,368 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:48:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 48 | scanf("%lf%lf%lf", &org.x, &org.y, &org.z); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:52:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 52 | scanf("%lf%lf%lf", &p.x, &p.y, &p.z); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <string>#include <vector>#include <algorithm>#include <numeric>#include <set>#include <map>#include <queue>#include <iostream>#include <sstream>#include <cstdio>#include <cmath>#include <ctime>#include <cstring>#include <cctype>#include <cassert>#include <limits>#include <functional>#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))#if defined(_MSC_VER) || __cplusplus > 199711L#define aut(r,v) auto r = (v)#else#define aut(r,v) __typeof(v) r = (v)#endif#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)#define all(o) (o).begin(), (o).end()#define pb(x) push_back(x)#define mp(x,y) make_pair((x),(y))#define mset(m,v) memset(m,v,sizeof(m))#define INF 0x3f3f3f3f#define INFL 0x3f3f3f3f3f3f3f3fLLusing namespace std;typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }struct Point {double x, y, z;};double sq(double x) { return x * x; }int main() {int N;while(~scanf("%d", &N)) {Point org;scanf("%lf%lf%lf", &org.x, &org.y, &org.z);vector<Point> points(N);rep(i, N) {Point p;scanf("%lf%lf%lf", &p.x, &p.y, &p.z);p.x -= org.x;p.y -= org.y;p.z -= org.z;points[i] = p;}vector<vector<double> > dist(N, vector<double>(N));rep(i, N) rep(j, i) {const Point &p = points[i], &q = points[j];dist[i][j] = sqrt(sq(p.x - q.x) + sq(p.y - q.y) + sq(p.z - q.z));}double ans = 0;rep(i, N) reu(j, i + 1, N) reu(k, j + 1, N) {const double A[3][3] = {{ points[i].x, points[i].y, points[i].z },{ points[j].x, points[j].y, points[j].z },{ points[k].x, points[k].y, points[k].z },};double a = dist[j][i], b = dist[k][j], c = dist[k][i];double s = (a + b + c) / 2;double area = sqrt(s * (s - a) * (s - b) * (s - c));double det = 0;det += A[0][0] * A[1][1] * A[2][2];det -= A[0][0] * A[1][2] * A[2][1];det -= A[0][1] * A[1][0] * A[2][2];det += A[0][1] * A[1][2] * A[2][0];det += A[0][2] * A[1][0] * A[2][1];det -= A[0][2] * A[1][1] * A[2][0];double height = abs(det) / 2 / area;ans += height;}printf("%.10f\n", ans);}return 0;}