题意

二维空间中有\(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. SpringBoot | 第十五章:基于Postman的RESTful接口测试

    前言 从上一章节开始,接下来的几个章节会讲解一些开发过程中配套工具的使用.俗话说的好,工欲善其事,必先利其器.对于开发人员而言,有个好用的工具,也是一件事半功倍的事,而且开发起来也很爽,效率也会提升很 ...

  2. 解决gradle下载慢的问题

    解决方法要做两部 一 打开用户主目录 linux平台/home/用户名/.gradle windows平台c:\Users\用户名\.gradle macos平台/Users/用户名/.gradle ...

  3. linux下使用shell脚本批处理命令

    1.新建脚本touch first.sh 2.写入命令vi first.sh #!/bin/bash #publish service and api echo "copy file&quo ...

  4. 16.Ubuntu LTS 16.04安装搜狗输入法全过程记录(纯新手)

    这是我第四次打算转到Ubuntu上了,应该不会像以前那样装个系统就拜拜了.打算先把C和Vim重新学起来,数据结构那本书看完写完,第二步是学python和算法导论,暂定如此. 昨天晚上系统装完以后想着要 ...

  5. hibernate课程 初探单表映射2-4 transaction简介

    1 hibernate是非自动提交.如果transaction不写的话,会只创建表结构而不插入语句.   如果不写transaction而想实现插入的功能的话,需要重写session的dowork方法 ...

  6. androidStudio修改包名 Android 如何修改包名(同一个手机可以跑2个eros 项目)。

    修改applicationId(gradle.properties). 2.即时同步更新过去,否则不报错

  7. 移动端toast 提示,HTML css 全屏垂直水平居中

  8. Miner3D Developer 开发工具

    ——可视化的数据挖掘整合工具 在开发项目中,客户的要求多种多样.当开发者面临高挑战的工作时,完全可以选择Miner3D这样的软件,依赖其强大的数据可视化的特点,以及其他的明显的技术优势,提供给最终用户 ...

  9. Linux 下查找指令

    原文链接:http://www.cnblogs.com/sunleecn/archive/2011/11/01/2232210.html whereis <程序名称>查找软件的安装路径-b ...

  10. 爱加密so保护简单脱壳测试

    1.   最近研究so文件的保护,在网上搜索发现爱加密支持对so文件的保护,然后联系客户,本来是想让客户保护一个自己的so文件来做测试的,结果客户各种不愿意,说要签什么XX协议后才能给so保护,各种蛋 ...