POJ 1379 Run Away 模拟退火

题意:链接

方法:模拟退火。

#论成为一个欧洲人的必要性。

解析:

首先,普通的模拟退火,你要坚定你是一个欧洲人的信仰。

然后正常退火就好了。

根据样例修改参数- -!

WA

对拍修改参数

WA

瞎特么修改参数

AC

#论成为一个欧洲人的重要性。

代码:

#include <cmath>
#include <cstdio>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1010
#define eps 1e-13
#define pro 0.995751
using namespace std;
int t,n;
//This struct presents a point.
struct Point
{
    double x,y;
    friend istream& operator >> (istream &_,Point &a)
    {
        scanf("%lf%lf",&a.x,&a.y);
        return _;
    }
    friend ostream& operator << (ostream &_,Point a)
    {
        printf("The safest point is (%.1lf, %.1lf).\n",a.x,a.y);
        return _;
    }
    Point(){}
    Point(double _x,double _y):x(_x),y(_y){}
    Point operator + (const Point &a)
    {return Point(x+a.x,y+a.y);}
    Point operator - (const Point &a)
    {return Point(x-a.x,y-a.y);}
    Point operator * (double rate)
    {return Point(x*rate,y*rate);}
    double operator * (const Point &a)
    {return x*a.x+y*a.y;}
    double operator ^ (const Point &a)
    {return x*a.y-y*a.x;} 
}pt[N],border;
//This function is going to get the distance of two points.
double Get_Dis(Point a,Point b)
{
    return sqrt((a-b)*(a-b));
}
//The use of this function is to get the sum of the distance between the base point and the given point.
double Get_Sum(Point now)
{
    double ret=0x7f7f7f7f;
    for(int i=1;i<=n;i++)ret=min(ret,Get_Dis(now,pt[i]));
    return ret;
}
//This function is goint to simulate the process of tuihuo(chinese2333);
Point Tui_Huo(Point now,double basement)
{
    if(basement<eps)return now;
    double basex=rand()%1000/1000.0;
    double basey=rand()%1000/1000.0;
    int jd=rand()%2;
    if(jd)basex=-basex;
    jd=rand()%2;
    if(jd)basey=-basey;
    Point tmp(basex,basey);
    Point to=now+tmp*basement;
    to.x=min(border.x,max(0.0,to.x));
    to.y=min(border.y,max(0.0,to.y));
    double sumnow=Get_Sum(now),sumto=Get_Sum(to);
    if(sumto>sumnow||fabs(sumto-sumnow)<eps)return Tui_Huo(to,basement*pro);
    else
    {
        double delta=sumnow-sumto;
        double rp=rand()%1000/1000.0;
        if(exp(-delta/basement)<rp)
        {
            return Tui_Huo(to,basement*pro);
        }else return Tui_Huo(now,basement*pro);
    }
}
int main()
{
    srand(999329);
    scanf("%d",&t);
    while(t--)
    {
        cin>>border;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)cin>>pt[i];
        Point tmp(border.x/2.0,border.y/2.0);
        Point ans=Tui_Huo(tmp,(border.x+border.y)/10.0);
        cout<<ans;
    }
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值