[技巧性枚举] ZOJ 3672 Pan's Labyrinth

在这款迷宫逃脱游戏中,玩家需要选择三个点构成一个三角形,并找到具有最大高度的三角形来解开金属门。通过预处理找出每个点的最远点并计算可能的最大高度。

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3762

Pan's Labyrinth

Time Limit: 2 Seconds       Memory Limit: 65536 KB       Special Judge

Ofelia is chased by her evil stepfather, and now she finds herself lost in a labyrinth. She needs your help to run away from her tragic family.

There's a huge metal door standing in front of the exit of the labyrinth. There are n dots on the metal door. Pan (the god of the labyrinth) asks Ofelia to find out a triangle which has the largest height. The triangle's three vertexes must be the dots on the door, and its area must be positive. Ofelia should tell Pan the triangle's height so Pan will let Ofelia go.

Input

There are multiple cases (About 100 cases). For each case, the first line contains an integer n (3<=n<=500). In the next n lines, each line contains two real number x[i]y[i] (0<=x[i], y[i]<=10000) which indicates each dot's coordinate. There is no two dots in the same coordinate. The answers are strictly greater than 0.

Output

For each test case, output one line with the maximum triangle height. Any solution with a relative or absolute error of at most 1e-6 will be accepted.

Sample Input
6
0.000 4.000
2.000 4.000
1.000 0.000
1.000 8.000
0.900 7.000
1.100 7.000
7
6967.54555 3457.71200
3.52325 1273.85912
7755.35733 9812.97643
753.00303 2124.70937
7896.71246 8877.78054
5832.77264 5213.70478
4629.38110 8159.01498

Sample Output
7.00000
8940.96643

Hint
In case 1. Choose the  dot 3, 5, 6  to make up a triangle, and this triangle has the largest height 7.000. In case 2. We choose dot 2, 3, 5.


题目意思:

给n个点,选3个点组成一个三角形,求出最长的高。

解题思路:

高最长的三角形的底边的两点中必有一个点是,距离顶点最远距离的点。证明见:http://blog.youkuaiyun.com/synapse7/article/details/20942443
先预处理出最远的点,far[i]表示距离点i最远的点,o(n)枚举其中一个点,o(1)找出最远距离的点,再o(n)枚举另一个点。

叉积求面积,再求高。

代码:

//#include<CSpreadSheet.h>

#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;

#define Maxn 550

struct Point
{
    double x,y;
}pp[Maxn];
double dis[Maxn][Maxn];
int far[Maxn],n; //far[i]表示距离点最远的点的坐标

double Cal(int i,int j) //计算两点的距离
{
    return sqrt((pp[i].x-pp[j].x)*(pp[i].x-pp[j].x)+(pp[i].y-pp[j].y)*(pp[i].y-pp[j].y));

}

double Cha(Point a,Point b) //计算两个向量的叉积
{
    return a.x*b.y-a.y*b.x;
}

double solve(int a,int b,int c)
{
    Point aa,bb;
    aa.x=pp[a].x-pp[b].x,aa.y=pp[a].y-pp[b].y;
    bb.x=pp[c].x-pp[b].x,bb.y=pp[c].y-pp[b].y;

    double are=abs(Cha(aa,bb)); //面积的2倍

    return max(are/dis[a][b],max(are/dis[a][c],are/dis[b][c])); //最长的高

}

int main()
{
   //freopen("in.txt","r",stdin);
   //freopen("out.txt","w",stdout);
   while(~scanf("%d",&n))
   {
       for(int i=1;i<=n;i++)
            scanf("%lf%lf",&pp[i].x,&pp[i].y);
       for(int i=1;i<=n;i++) //预处理出每个点最远距离的点
       {
           double dd=-1;
           int re;

           for(int j=1;j<=n;j++)
           {
               if(i==j)
                    continue;
               double temp=Cal(i,j);
               dis[i][j]=temp;

               if(temp>dd)
               {
                   dd=temp;
                   re=j;
               }
           }
           far[i]=re;
       }
       double ans=-1;

       for(int i=1;i<=n;i++)
       {
           int ff=far[i];

           for(int j=1;j<=n;j++)
           {
               if(j==i||j==ff)
                    continue;
               double temp=solve(i,j,ff);
               if(temp>ans)
                   ans=temp;
           }
       }
       printf("%.6lf\n",ans);
   }

   return 0;
}




内容概要:本文提出了一种基于融合鱼鹰算法和柯西变异的改进麻雀优化算法(OCSSA),用于优化变分模态分解(VMD)的参数,进而结合卷积神经网络(CNN)与双向长短期记忆网络(BiLSTM)构建OCSSA-VMD-CNN-BILSTM模型,实现对轴承故障的高【轴承故障诊断】基于融合鱼鹰和柯西变异的麻雀优化算法OCSSA-VMD-CNN-BILSTM轴承诊断研究【西储大学数据】(Matlab代码实现)精度诊断。研究采用西储大学公开的轴承故障数据集进行实验验证,通过优化VMD的模态数和惩罚因子,有效提升了信号分解的准确性与稳定性,随后利用CNN提取故障特征,BiLSTM捕捉时间序列的深层依赖关系,最终实现故障类型的智能识别。该方法在提升故障诊断精度与鲁棒性方面表现出优越性能。; 适合人群:具备一定信号处理、机器学习基础,从事机械故障诊断、智能运维、工业大数据分析等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①解决传统VMD参数依赖人工经验选取的问题,实现参数自适应优化;②提升复杂工况下滚动轴承早期故障的识别准确率;③为智能制造与预测性维护提供可靠的技术支持。; 阅读建议:建议读者结合Matlab代码实现过程,深入理解OCSSA优化机制、VMD信号分解流程以及CNN-BiLSTM网络架构的设计逻辑,重点关注参数优化与故障分类的联动关系,并可通过更换数据集进一步验证模型泛化能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值