题意

二维空间中有\(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. HTML常用标签参考学习

    1.跑马灯标签 功能<marquee>...</marquee> 普通卷动<marquee behavior=slide>...</marquee> 滑 ...

  2. webpack webpack-dev-server报错

    Error: getaddrinfo ENOTFOUND localhost at errnoException (dns.js:28:10) at GetAddrInfoReqWrap.onlook ...

  3. Ionic 解决gradle下载慢的问题

    问题 使用Ioinc添加安卓平台或者编译的时候,提示gradle-XXX-all.zip下载,此进度缓慢. 解决 下载gradle对应的zip文件. 参考资源:http://services.grad ...

  4. 给浏览器绑定鼠标滚动事件(兼容FireFox)

    var bs = new Browser(); if(bs.userBrowser() == 'firefox'){ document.body.addEventListener("DOMM ...

  5. mysql 批量修改 表字段/表/数据库 字符集和排序规则

    今天接到一个任务是需要把数据库的字符编码全部修改一下,写了以下修正用的SQL,修正顺序是   表字段 > 表 > 数据库. 表字段修复: #改变字段数据 SELECT TABLE_SCHE ...

  6. hibernate课程 初探单表映射1-7 hibernate配置文件新建

    hibernate  配置文件新建 1 右键src==>new==>other==>hibernate configuration File==>next==>next= ...

  7. GITHUB中GIT BASH基础命令行

    PS:转自https://www.cnblogs.com/WangXinPeng/p/8016293.html 1.常用命令行工具: ①cmd     ②powershell      ③git ba ...

  8. 前端JS电商放大镜效果

    前端JS电商放大镜效果: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  9. mui的ajax例子1

    mui.ajax()方法,get请求 前端页面: <!DOCTYPE html><html><head> <meta charset="utf-8& ...

  10. [转]git修改远程仓库地址

    原文链接:http://www.cnblogs.com/lazb/articles/5597878.html 问:Coding远程仓库地址变了,本地git仓库地址如何更新为最新地址 git修改远程仓库 ...