极角排序

题目链接: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
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值