POJ 1379 模拟退火法

Run Away

Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 5631   Accepted: 1728

Description

One of the traps we will encounter in the Pyramid is located in the Large Room. A lot of small holes are drilled into the floor. They look completely harmless at the first sight. But when activated, they start to throw out very
hot java, uh ... pardon, lava. Unfortunately, all known paths to the Center Room (where the Sarcophagus is) contain a trigger that activates the trap. The ACM were not able to avoid that. But they have carefully monitored the positions of all the holes. So
it is important to find the place in the Large Room that has the maximal distance from all the holes. This place is the safest in the entire room and the archaeologist has to hide there.

Input

The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing three integers X, Y, M separated by space. The numbers satisfy conditions: 1
<= X,Y <=10000, 1 <= M <= 1000. The numbers X and Yindicate the dimensions of the Large Room which has a rectangular shape. The number M stands for the number of holes. Then exactly M lines follow, each containing two integer numbers Ui and Vi (0 <= Ui <=
X, 0 <= Vi <= Y) indicating the coordinates of one hole. There may be several holes at the same position.

Output

Print exactly one line for each test case. The line should contain the sentence "The safest point is (P, Q)." where P and Qare the coordinates of the point in the room that has the maximum distance from the nearest hole, rounded
to the nearest number with exactly one digit after the decimal point (0.05 rounds up to 0.1).

Sample Input

3
1000 50 1
10 10
100 100 4
10 10
10 90
90 10
90 90
3000 3000 4
1200 85
63 2500
2700 2650
2990 100

Sample Output

The safest point is (1000.0, 50.0).
The safest point is (50.0, 50.0).
The safest point is (1433.0, 1669.8).

在给定范围内找一个点,距离所有点的最小值最大,

做过类似题目,但是发现以前的方法行不通了,看别人的写法,先找20个随机种子,然后逐步更新,最后取最优解。学习了。

代码:

/* ***********************************************
Author :_rabbit
Created Time :2014/5/11 21:41:17
File Name :3.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
typedef long long ll;
struct point
{
       double x,y,dis;
}a[2000],b[100],ans;
int n,X,Y;
double dis(point c){
       double sum=1e8;
       for (int i=1;i<=n;++i){
		   double dd=sqrt((c.x-a[i].x)*(c.x-a[i].x)+(c.y-a[i].y)*(c.y-a[i].y));
		   if(sum>dd)sum=dd;
	   }
       return sum;
}
void Solve()
{
    for (int i=1;i<=20;++i)
    {
        b[i].x=rand()%X+1,b[i].y=rand()%Y+1;
        b[i].dis=dis(b[i]);
    }
    point t;
    for (double i=max(X,Y);i>=1e-2;i*=0.9)
        for (int j=1;j<=20;j++)
            for (int k=1;k<=20;k++)
            {
                double ran=rand();
                t.x=b[j].x+cos(ran)*i;
                t.y=b[j].y+sin(ran)*i;
                if (0>t.x || t.x>X || 0>t.y || t.y>Y)
                    continue;
                t.dis=dis(t);
                if (t.dis>b[j].dis) b[j]=t;
            }
    ans.dis=-1;
    for (int i=1;i<=20;++i)if (ans.dis<b[i].dis) ans=b[i];
}  

int main()
{
    int test;
    scanf("%d",&test);
    while (test--)
    {
        scanf("%d %d %d",&X,&Y,&n);
        for (int i=1;i<=n;i++)
             scanf("%lf %lf",&a[i].x,&a[i].y);
        Solve();
        printf("The safest point is (%.1f, %.1f).\n",ans.x,ans.y);
    }
    return 0;
}

POJ 1379 模拟退火法

时间: 2024-12-28 23:57:29

POJ 1379 模拟退火法的相关文章

POJ 2420 模拟退火法

A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3272   Accepted: 1664 Description Luke wants to upgrade his home computer network from 10mbs to 100mbs. His existing network uses 10base2 (coaxial) cables that allow you

POJ 1379 模拟退火算法

求规定平面上一点到已知点的最小距离最大的点. 模拟退火的流程是,随机构造几组解作为初始解空间,每次对当前解空间进行随机扩展,若发现更优解则替换. 进行的次数由参数人为控制,而随机扩展的幅度也是随着次数逐渐减小的. #include<iostream> #include<cstdio> #include<cstring> #include<queue> #include<cmath> #include<string> #include&

Shuffle&#39;m Up (poj 3087 模拟)

Language: Default Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5968   Accepted: 2802 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting

G - Shuffle&#39;m Up POJ 3087 模拟洗牌的过程,算作暴力搜索也不为过

G - Shuffle'm Up Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3087 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by start

POJ 1379

模拟退火算法. 随机MAX个点,然后,退火移动,选取距离所有点中最短中最长者即可.理解和我上一篇一样. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <time.h> using namespace std; const int MAXN=1010; const int MA

unity, 模拟退后台

//simulateSwitchToBackground.cs using UnityEngine;using System.Collections;using System.Collections.Generic;public class simulateSwitchToBackground : MonoBehaviour {void sendApplicationPauseMessage(bool isPause){Transform[] transList= GameObject.Find

POJ 1016 模拟字符串

Numbers That Count Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20396   Accepted: 6817 Description "Kronecker's Knumbers" is a little company that manufactures plastic digits for use in signs (theater marquees, gas station price

POJ 1379 Run Away

题意:有n个陷阱,在X,Y范围内要求出一个点使得这个点到陷阱的最小距离最大. 思路:模拟退火,随机撒入40个点,然后模拟退火随机化移动. (这题poj坑爹,加了srand(time(NULL))不能交G++,不加srand(time(NULL))又会WA,交了C++不能用acos(-1),只能用3.1415926代替,真是坑爹.) #include<algorithm> #include<cstdio> #include<cmath> #include<cstri

poj 3087 模拟

背景:bfs专题的题,可是直接模拟就好了啊. 思路:管件在于记录第一个s12串,当再次出现第一个s12串时说明进入了循环之中,不能呢达到目标状态. 学习:1.strcmp时要注意,该字符串的有效部分是不是以'\0'结尾的. #include<map> #include<set> #include<stack> #include<queue> #include<vector> #include<cstdio> #include<c