描述

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. python中的random

    random.randint(a,b)    用于生成一个指定范围内的整数,a为下限,b为上限,生成的随机整数a<=n<=b;若a=b,则n=a:若a>b,报错 import ran ...

  2. window之间、iframe之间的JS通信

    一.Window之间JS通信 在开发项目过程中,由于要引入第三方在线编辑器,所以需要另外一个窗口(window),而且要求打开的window要与原来的窗口进行js通信,那么如何实现呢? 1.在原窗口创 ...

  3. 使用脚本在Linux服务器上自动安装Kubernetes的包管理器Helm

    Helm之于Kubernetes好比yum之于Red Hat Enterprise Linux,或者apt-get之于Ubuntu. Helm是由helm CLI和Tiller组成,是典型的Clien ...

  4. Oracle CRS/GI 进程介绍

    在10g和11.1,Oracle的集群称为CRS(Oracle Cluster Ready Service), 在11.2,Oracle的集群称为GI(Grid Infrastructure). 对于 ...

  5. CF Gym 100637J Superfactorial numeral system (构造)

    题意:给一个式子,ak,k>2时,0<=ak<k:ai都是整数,给你p,q让你求一组ak. 题解:构造,每次除掉q取整得到ai,然后减一减 #include<cstdio> ...

  6. Java的引用StrongReference、 SoftReference、 WeakReference 、PhantomReference

    1. Strong Reference StrongReference 是 Java 的默认引用实现,  它会尽可能长时间的存活于 JVM 内, 当没有任何对象指向它时 GC 执行后将会被回收 @Te ...

  7. 使用lua做序列化和反序列化

    -- lua对象序列化 function serialize(obj) local lua = "" local t = type(obj) if t == "numbe ...

  8. Linux下手动备份还原硬盘主引导记录MBR跟硬盘分区表DPT教程

    Linux下手动备份还原硬盘主引导记录MBR跟硬盘分区表DPT教程 二 18 奶牛 Linux, Ubuntu, Windows 1,885 views查看评论 最近奶牛一直在折腾linux下的gru ...

  9. NOIP2013 表达式求值

    题目描述 Description 给定一个只包含加法和乘法的算术表达式,请你编程计算表达式的值. 输入描述 Input Description 输入仅有一行,为需要你计算的表达式,表达式中只包含数字. ...

  10. Linux远程传输命令scp

    指令:scp在不同的linux主机间复制文件带有Security的文件copy,基于ssh登录. 有些linux发行版没有自带scp,因此需要安装scp# yum -y install openssh ...