zoukankan      html  css  js  c++  java
  • 模拟退火 Buried memory

    Each person had do something foolish along with his or her growth.But,when he or she did this that time,they could not predict that this thing is a mistake and they will want this thing would rather not happened.
    The world king Sconbin is not the exception.One day,Sconbin was sleeping,then swakened by one nightmare.It turned out that his love letters to Dufein were made public in his dream.These foolish letters might ruin his throne.Sconbin decided to destroy the letters by the military exercises's opportunity.The missile is the best weapon.Considered the execution of the missile,Sconbin chose to use one missile with the minimum destruction.
    Sconbin had writen N letters to Dufein, she buried these letters on different places.Sconbin got the places by difficult,he wants to know where is the best place launch the missile,and the smallest radius of the burst area. Let's help Sconbin to get the award.

    InputThere are many test cases.Each case consists of a positive integer N(N<500,^V^,our great king might be a considerate lover) on a line followed by N lines giving the coordinates of N letters.Each coordinates have two numbers,x coordinate and y coordinate.N=0 is the end of the input file.OutputFor each case,there should be a single line in the output,containing three numbers,the first and second are x and y coordinates of the missile to launch,the third is the smallest radius the missile need to destroy all N letters.All output numbers are rounded to the second digit after the decimal point.
    Sample Input

    3
    1.00 1.00
    2.00 2.00
    3.00 3.00
    0

    Sample Output

    2.00 2.00 1.41

    思路:枚举圆心 找最长半径 看能否 朝着这个方向继续更新答案


    code:
    //
    #include<bits/stdc++.h>
    using namespace std;
    int n;
    #define maxnn  1000
    double x[maxnn],y[maxnn];
    double delta=0.98;
    double T=1;
    double eps=1e-9;
    double dist(double x1,double y1,double x2,double y2)
    {
        return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    }
    void init()
    {
        memset(x,0,sizeof(x));
        memset(y,0,sizeof(y));
    }
    void tui()
    {
        double t=100;
        double ans=100000000;
        double sx=x[1];
        double sy=y[1];
        double nowx=0;
        double nowy=0;
        while(t>eps)
        {
                double now=0;
                double nowx=sx;
                double nowy=sy;
                int pal=0;
                for(int i=1;i<=n;i++)
                {
                    if(now<dist(x[i],y[i],nowx,nowy))
                    {
                        now=max(now,dist(x[i],y[i],nowx,nowy));
                        pal=i;
                    }
                }
                if(now<ans)
                {
                    ans=now;
                }
                sx+=t*(x[pal]-nowx)/(dist(nowx,nowy,x[pal],y[pal]));
                sy+=t*(y[pal]-nowy)/(dist(nowx,nowy,x[pal],y[pal]));  //朝着一个方向移动
            t*=delta;
        }
        printf("%.2f %.2f %.2f
    ",sx,sy,ans);
    }
    int main()
    {
        while(cin>>n)
        {
            if(n==0)
            return 0;
            init();
            for(int i=1;i<=n;i++)
            {
                scanf("%lf%lf",&x[i],&y[i]);    
            } 
            tui();
        }
     } 
    刀剑映出了战士的心。而我的心,漆黑且残破
  • 相关阅读:
    JBPM使用
    eclipse spring3.X redis 整合-配置
    30分钟学会如何使用Shiro
    Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)
    Eclipse上Maven环境配置使用 (全)
    redis未设置idle超时时间导致连接过多
    linux下搭建redis并解决无法连接redis的问题
    redis配置用户认证密码
    spring配置redis
    Linux nohup和&后台运行,进程查看及终止,进程信息输出,控制台信息输出
  • 原文地址:https://www.cnblogs.com/OIEREDSION/p/11290434.html
Copyright © 2011-2022 走看看