The Moving Points - HDU - 4717 (模拟退火)
题意
二维空间中有\(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 (模拟退火)的更多相关文章
- The Moving Points HDU - 4717
There are N points in total. Every point moves in certain direction and certain speed. We want to kn ...
- HDU 4717 The Moving Points (三分)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDOJ 4717 The Moving Points
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4717The Moving Points warmup2 1002题(三分)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- The Moving Points hdu4717
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDUOJ---The Moving Points
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU-4717 The Moving Points(凸函数求极值)
The Moving Points Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- F. Moving Points 解析(思維、離散化、BIT、前綴和)
Codeforce 1311 F. Moving Points 解析(思維.離散化.BIT.前綴和) 今天我們來看看CF1311F 題目連結 題目 略,請直接看原題. 前言 最近寫1900的題目更容易 ...
- HDU 4717 The Moving Points(三分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 题意:给出n个点的坐标和运动速度(包括方向).求一个时刻t使得该时刻时任意两点距离最大值最小. ...
随机推荐
- vuex文档(附加个人理解)
Vuex是什么? Vuex 是一个专为 Vue.js应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化.Vuex 也集成到Vue 的 ...
- Java并发包——线程同步和锁
Java并发包——线程同步和锁 摘要:本文主要学习了Java并发包里有关线程同步的类和锁的一些相关概念. 部分内容来自以下博客: https://www.cnblogs.com/dolphin0520 ...
- ssm(Spring、Springmvc、Mybatis)实战之淘淘商城-第九天(非原创)
文章大纲 一.课程介绍二.今日功能介绍三.项目源码与资料下载四.参考文章 一.课程介绍 一共14天课程(1)第一天:电商行业的背景.淘淘商城的介绍.搭建项目工程.Svn的使用.(2)第二天:框架的整合 ...
- Mavlink协议理解
来源:blog.csdn.net/super_mice/article/details/44836585 之前看了mavlink协议,网上关于mavlink的资料不多.本文大概总结了下对mavlink ...
- Mavlink消息包解析
Byte Index 字节索引 Content 内容 Value 值 Explanation 说明 0 包起始标志 v1.0: 0xFE (v0.9: 0x55) 指示新消息帧的开始.在v1.0版本中 ...
- Vue.js(2.x)之Class 与 Style 绑定
1.前面看数据绑定时还很困惑v-bind处理class时可以使用json格式的值,为什么换成id.href等其他属性就不行.看了下文档解释后明白了些: 2.对象语法主要有以下三种形式: 1)直接在v- ...
- JAVA中的多态概念
多态性是指同一操作作用于某一类对象,可以有不同的解释,产生不同的执行结果. 多态存在的三个必要条件 需要存在继承和实现关系 同样的方法调用而执行不同操作,运行不同代码. 在运行时父类或者接口的引用变量 ...
- Qt安装教程
一.Qt下载 官网下载链接http://download.qt.io/archive/qt/,下载最新版 5.10 官网的下载网站有的时候可能会抽风,也可以选择国内的镜像下载源http://mirro ...
- SQL重复记录查询-count与group by having结合查询重复记录
查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断select * from peoplewhere peopleId in (select peopleId from p ...
- PHP与MYSQL结合操作——文章发布系统小项目(实现基本增删查改操作)
php和mysql在一起几十年了,也是一对老夫老妻了,最近正在对他们的爱情故事进行探讨,并做了一个很简单的小东西——文章发布系统,目的是为了实现mysql对文章的基本增删查改操作 前台展示系统有:文章 ...