题意

二维空间中有\(n\)个运动的点,每个点有一个初始坐标和速度向量。求出一个时间\(T\),使得此时任意两点之间的最大距离最小。输出\(T\)和最大距离。

题解

模拟退火。

这个题告诉了我,初始步长要够大。这是很重要的。

//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream> #define FOPI freopen("in.txt", "r", stdin)
#define FOPO freopen("out.txt", "w", stdout) using namespace std;
typedef long long LL;
const int maxn = 300 + 5;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const double start_T = 2000; struct Point
{
double x, y, z;
Point() {}
Point(double _x, double _y, double _z = 0):x(_x), y(_y), z(_z) {}
}a[maxn];
double vx[maxn], vy[maxn]; int n; double dist(Point a, Point b)
{
return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + 1e-10);
} Point pos[maxn];
double getMax(double ti)
{
for (int i = 1; i <= n; i++)
pos[i] = Point(a[i].x + vx[i]*ti, a[i].y + vy[i]*ti); double res = 0;
for (int i = 1; i <= n; i++)
for (int j = i+1; j <= n; j++)
res = max(res, dist(pos[i], pos[j]));
return res;
} double SA()
{
double T = start_T, rate = 0.92;
double ti = 0, ans = getMax(ti), to; while(T > eps)
{
double tmp = inf;
for (int i = 1; i <= 5; i++)
{
double nextt = ti + T / start_T * (rand() % inf);
double lastt = ti - T / start_T * (rand() % inf);
double d1 = getMax(nextt), d2 = getMax(lastt); if (d1 < tmp) tmp = d1, to = nextt;
if (d2 < tmp && lastt > eps) tmp = d2, to = lastt;
} if (tmp < ans || (rand()%1000)/1000.0 < exp(-fabs(ans-tmp)/T*start_T))
{
ans = tmp;
ti = to;
}
T *= rate;
}
printf("%.2f %.2f\n", ti, ans);
return ans;
} int t;
int main()
{
// FOPI;
srand(time(NULL));
scanf("%d", &t);
for (int ca = 1; ca <= t; ca++)
{
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lf%lf%lf%lf", &a[i].x, &a[i].y, &vx[i], &vy[i]); printf("Case #%d: ", ca);
SA();
}
}

The Moving Points - HDU - 4717 (模拟退火)的更多相关文章

  1. The Moving Points HDU - 4717

    There are N points in total. Every point moves in certain direction and certain speed. We want to kn ...

  2. HDU 4717 The Moving Points (三分)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. HDOJ 4717 The Moving Points

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. HDU 4717The Moving Points warmup2 1002题(三分)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. The Moving Points hdu4717

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. HDUOJ---The Moving Points

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. HDU-4717 The Moving Points(凸函数求极值)

    The Moving Points Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. F. Moving Points 解析(思維、離散化、BIT、前綴和)

    Codeforce 1311 F. Moving Points 解析(思維.離散化.BIT.前綴和) 今天我們來看看CF1311F 題目連結 題目 略,請直接看原題. 前言 最近寫1900的題目更容易 ...

  9. HDU 4717 The Moving Points(三分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题意:给出n个点的坐标和运动速度(包括方向).求一个时刻t使得该时刻时任意两点距离最大值最小. ...

随机推荐

  1. js中的load先执行还是Jquery的ready先执行问题

    onload需要页面上所有的资源都加载上之后执行,而ready则是DOM文档树已经解析完成时,说ready比onload快最显著的是比如一个页面上有一个很大的图片,加载要好久,onload只有在图片加 ...

  2. css清除浮动好方法

    1.clear:both ==>IE6,7会有高度,所以去高度需要.clear{ clear:both; height:0px; margin:0; padding:0; width:0; bo ...

  3. axios拦截器+mockjs

    //main.js中 //引入你mock.js文件 require('./mock.js') //封装api请求 //src/axios/api.js import axios from 'axios ...

  4. Css文件目录结构

    一般一个网站会有这么三个样式: global.css | reset.css(格式化样式) common.css(公共组件样式) layout.css(当前页面样式) global.css | res ...

  5. nginx配置文件语法高亮

    下载文件 nginx.vim https://vim.sourceforge.io/scripts/script.php?script_id=1886 安装 下载 nginx.vim 文件到 ~/.v ...

  6. COGS 1453. [USACO NOV]空牛栏

    ★★   输入文件:empty.in   输出文件:empty.out   简单对比时间限制:1 s   内存限制:64 MB [题目描述] FJ建的新牛棚里有N(2<=N<=3,000, ...

  7. .Net创建Windows服务完成批量导出功能(错误速查)

    无法打开计算机“.”上的服务控制管理器.此操作可能需要其他特权. 无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为 ...

  8. m3u8视频下载方法

    部分网站的视频内容,采用了m3u8的格式.正常打开网页可以,但是如果想下载到本地,就存在一定问题了.这里可以再获取到m3u8地址之后,利用vlc软件,来下载m3u8的视频. 工具:Firefox浏览器 ...

  9. BZOJ 1229: [USACO2008 Nov]toy 玩具

    BZOJ 1229: [USACO2008 Nov]toy 玩具 标签(空格分隔): OI-BZOJ OI-三分 OI-双端队列 OI-贪心 Time Limit: 10 Sec Memory Lim ...

  10. 函数定义和调用 -------JavaScript

    本文摘要:http://www.liaoxuefeng.com/ 定义函数 在JavaScript中,定义函数的方式如下: function abs(x) { if (x >= 0) { ret ...