描述

You are working as a guide on a tour bus for retired people, and today you have taken your regular Nordic seniors to The Gate of Heavenly Peace. You let them have a lunch break where they could do whatever they like. Now you have to get them back to the bus, but they are all walking in random directions. You try to intersect them, and send them straight back to the bus. Minimize the time before the last person is in the bus. You will always be able to run faster than any of the tour guests, and they walk with constant speed, no matter what you tell them. The seniors walk in straight lines, and the only way of changing their direction is to give them promises of camphor candy. A senior will neither stop at nor enter the bus before given such a promise.

输入

A number of test cases consisting of: A line with an integer 1 ≤ n ≤ 8, the number of people on the tour. A line with an floating point number 1 < v ≤ 100, your maximum speed (you start in the bus at the origin). Then follow n lines, each containing four floating point numbers xi yi vi ai, the starting coordinates (−106 ≤ xi, yi ≤ 106), speed (1 ≤ vi < 100) and direction (0 ≤ ai < 2π) of each of the tour guests.

The input is terminated by a case with n = 0, which should not be processed. All floating point numbers in the input will be written in standard decimal notation, and have no more than 10 digits.

输出

For each test case, print a line with the time it takes before everybody is back in the bus (the origin). Round the answer to the nearest integer. The answer will never be larger than 106.

样例输入

1
50.0
125.0 175.0 25.0 1.96
3
100.0
40.0 25.0 20.0 5.95
-185.0 195.0 6.0 2.35
30.0 -80.0 23.0 2.76
0

样例输出

20
51

提示

Q: Should 2.5000000000 be rounded to 3? 
A: We have constructed the test cases such that it does not matter.

题目来源

Nordic 2006

这个题目最简洁的想法就是去枚举接哪些人的,也就是n!的写法,当时学长亲测是可以过的,而且代码也稍微短点

我dfs进行剪枝了,所以稍微快点吧

枚举所有情况,然后根据距离公式求得当前的时间

#include<bits/stdc++.h>
using namespace std;
struct Node
{
double x,y,v,d;
} p[];
int id[],N;
double mi;
double lb(Node g, Node s, Node *mg)
{
/*(s.x−g.x+vcd*t)*(s.x−g.x+vcd*t)+(s.y−g.y+vsd*t)*(s.y−g.y+vsd*t)=g.v*(t-g.d)*g.v*(t-g.d)
两者之间的距离公式
a=vcd*vcd+vsd*vsd-g.v*g.v=s.v*s.v*(sin(s.d)*sin(s.d)+cos(s.d)*cos(s.d))-g.v*g.v=s.v*s.v*-g.v*g.v;
b=2*((g.v*g.v*g.d)+(s.x-g.x)*vcd+(s.y-g.y)*vsd)
c=(s.x-g.x)*(s.x-g.x)+(s.y-g.y)*(s.y-g.y)-(g.v*g.d)*(g.v*g.d)*/
double c0,c1,c2,vsd,vcd,a,b,c,x,y,t;
vsd=s.v*sin(s.d);//y轴的分速度
vcd=s.v*cos(s.d);//x轴的分速度
c0=g.v*g.v*g.d;
c1=s.x-g.x;//两点的横坐标之差
c2=s.y-g.y;//两点的纵坐标之差
a=s.v*s.v-g.v*g.v;
b=*(c0+c1*vcd+c2*vsd);
c=c1*c1+c2*c2-c0*g.d;
t=-(b+sqrt(b*b-*a*c))/(*a);//求其正整数解
x=s.x+vcd*t;//也就是老人的速度加上他又走的
y=s.y+vsd*t;//也就是老人的速度加上他又走的
mg->x=x;//求得现在的位置x
mg->y=y;//求得现在的位置y
mg->v=g.v;//求得导游的速度
mg->d=t;//求得时间t
return t+sqrt(x*x+y*y)/s.v;//求得时间+老人走回来的时间
}
double la(Node g, double tt, int deep)
{
double t;
if(deep==) mi=1e7;
if(deep==N&&mi>tt) mi=tt;
for(int i=deep; i<N; i++)
{
swap(id[i],id[deep]);
Node mg;
t=lb(g,p[id[deep]],&mg);//求得当前的时间
if(t<mi) la(mg,t>tt?t:tt,deep+);//比最小时间小,说明当前时间合法,可以继续递归
swap(id[i],id[deep]);//重新交换回来检查是不是还能更小
}
return mi;
}
int main()
{
for(int i = ; i<;i++)id[i]=i;
while(scanf("%d",&N),N)
{
double v;
scanf("%lf",&v);
for(int i=; i<N; i++)
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i].v,&p[i].d);
Node g= {,,v,};
printf("%.0f\n", la(g,,));
}
return ;
}

TOJ1017: Tour Guide的更多相关文章

  1. 使用TCPDF插件生成pdf以及pdf的中文处理

    目录(?)[+] 多种多样的pdf开发库 WKHTMLTOPDF 2FPDF 3TCPDF 中文问题   做了这么多年项目,以前只是在别人的项目中了解过PHP生成pdf文件,知道并不难,但是涉及到了p ...

  2. express-17 持久化

    简介 所有网站和Web应用程序(除了最简单的)都需要某种持久化方式,即某种比易失性内存更持久的数据存储方式,这样当遇到服务器宕机.断电.升级和迁移等情况时数据才能保存下来. 文件系统持久化 实现持久化 ...

  3. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  4. 每日英语:Secrets Of Effective Office Humor

    Margot Carmichael Lester loves making good-natured jokes at work. As owner of The Word Factory, a Ca ...

  5. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  6. 干货分享:深度解析Supplement Essay写作

    今天Hotessay小编给同学们介绍下附加文书的创作思路.因为附加文书基本上都是短essay,所以简洁才是硬道理! 通常,我们可以把美国大学的附加文书分为以下几类: 1.Tell us about y ...

  7. The Definitive C++ Book Guide and List

    学习c++的书单 转自 http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list Beginner ...

  8. Hibernate Validator 6.0.9.Final - JSR 380 Reference Implementation: Reference Guide

    Preface Validating data is a common task that occurs throughout all application layers, from the pre ...

  9. User guide for Netty 4.x

    Table of Contents Preface The Solution Getting Started Before Getting Started Writing a Discard Serv ...

随机推荐

  1. 【虚拟机-部署】通过 Powershell 来调整 ARM 模式下虚拟机的尺寸

    需求描述 在部署完 ARM 模式的虚拟机以后,可以通过 PowerShell 命令来调整虚拟机的尺寸,以下是通过 PowerShell 命令来调整 ARM 模式的虚拟机尺寸. Note 本文只限于 A ...

  2. 解决Layui的switch样式显示问题

    Layui官方文档是这么说的: <input type="checkbox" name="xxx" lay-skin="switch" ...

  3. Android商城开发系列(五)—— 商城首页回到顶部和搜索框布局实现

    今天我们来开发商城的首页[输入搜索框]布局和点击右下角图片回到顶部的效果 搜索功能在App中很常见,尤其是在商城类的项目当中,一般都会提供很强大的搜索功能,App的搜索布局一般都是在App的顶部,如下 ...

  4. 抓取GridView "编辑"模式下,TextBox修改后的数值

    [FAQ]抓取GridView "编辑"模式下,TextBox修改后的数值 -- ASP.NET专题实务「上集」Ch.10 抓取GridView "编辑"模式下 ...

  5. Array - RemoveDuplicatesfromSortedArray

    /** * 无额外空间,只要前n个是不重复的就行,不需要修改后面的数字 * @param nums 已排序的数组 * @return 去除重复数字后的长度 */ public int removeDu ...

  6. 二、antd pro 删除eslint检测

    删除package.json 里 " pre-commit": "npm run lint-staged" 这个对象就可以.

  7. appium---常用的adb命令

    在测试android-app的时候,adb命令可以帮助我们解决许多问题 什么是adb Android Debug Bridge,我们一般简称为adb,主要存放在sdk安装目录下的platform-to ...

  8. CMDB数据库设计

    title: CMDB 数据库设计 tags: Django --- CMDB数据库设计 具体的资产 服务器表和网卡.内存.硬盘是一对多的关系,一个服务器可以有多个网卡.多个内存.多个硬盘 hostn ...

  9. k8s1.13.0二进制部署-node节点(四)

    Master apiserver启用TLS认证后,Node节点kubelet组件想要加入集群,必须使用CA签发的有效证书才能与apiserver通信,当Node节点很多时,签署证书是一件很繁琐的事情, ...

  10. BCB:使用CppWebBrowser判断网页加载完成

    void __fastcall TForm1::CppWebBrowser1DocumentComplete(TObject *Sender, LPDISPATCH pDisp, Variant *U ...