题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805046577840128
#include<bits/stdc++.h> #define _TIME 0 #define _INPUT 0 #define _OUTPUT 0 clock_t START, END; void __stTIME(); void __enTIME(); void __IOPUT(); using namespace std; const int maxn = 5005; struct pt { int x,y; }p[maxn],d[maxn]; bool cmp(pt a,pt b) { return 1LL*a.y*b.x<1LL*a.x*b.y; } int main() { __stTIME();__IOPUT(); int n; scanf("%d",&n); for(int i = 1;i <= n;i++) { scanf("%d%d",&p[i].x,&p[i].y); } double ans = 2e18; for(int i = 1;i <= n;i++) { int tot = 0; for(int j = 1;j <= n;j++) { /**对第i个点,构造以i点为起点,j点为终点的向量 */ if(i == j ) continue; ++tot; d[tot].x = p[j].x - p[i].x; d[tot].y = p[j].y - p[i].y; } sort(d+1,d+1+tot,cmp); /**对n-1个向量进行极角排序 */ for(int j = 1;j <= tot-1;j++) { /**对相邻的向量进行遍历,找出最小的三角形面积 */ ans = min(ans, 0.5*(1LL*d[j].x*d[j+1].y - 1LL*d[j].y*d[j+1].x)); } } /// ///c++ 保存指定小数位方法 /// cout<<setiosflags(ios::fixed)<<setprecision(3)<<ans<<endl; printf("%.3f\n",ans); __enTIME(); } void __stTIME() { #if _TIME START = clock(); #endif } void __enTIME() { #if _TIME END = clock(); cerr<<"execute time = "<<(double)(END-START)/CLOCKS_PER_SEC<<endl; #endif } void __IOPUT() { #if _INPUT freopen("in.txt", "r", stdin); #endif #if _OUTPUT freopen("out.txt", "w", stdout); #endif }