描述

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. SharePoint Server 2016 WEB 网站浏览器支持

    SharePoint Server 2016支持多种常用的Web浏览器,如Internet Explorer,Google Chrome,Mozilla Firefox,Apple Safari和Mi ...

  2. COGS 2342. [SCOI2007]kshort

    ★★☆   输入文件:bzoj_1073.in   输出文件:bzoj_1073.out   简单对比时间限制:2 s   内存限制:512 MB [题目描述] 有n个城市和m条单向道路,城市编号为1 ...

  3. CDOJ 490 UESTC 490 Swap Game(思路,逆序对)

    题意:有两种颜色的小球形成环,求最小交互次数使球相连. 题解:先解决另一个简单的问题,如果是一个链,把红球标记为1,蓝球标记为0,要排成升序需要多少次交换呢?答案是逆序对总数,原因是一次交互最多消除一 ...

  4. 【转】 iOS学习之NSBundle介绍和使用

    bundle是一个目录,其中包含了程序会使用到的资源.这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in).对应bundle, cocoa提供了类NSBun ...

  5. flash jquery 调用摄像头 vue chrome49浏览器

    flash jquery 调用摄像头 vue chrome49浏览器 这个摄像头,不能一个页面加载多个,只能一个页面显示一次,所以 调用的时候,记得加v-if 把组件销毁,然后从新加载新的 <! ...

  6. C++调用C语言编译的so文件

    参考链接:https://blog.csdn.net/chenjinlong126/article/details/78990350 一.制作so文件:libadd_c.so或libadd_cpp.s ...

  7. VIM+ctags+cscope用法

    使用vim + cscope/ctags,就能够实现Source Insight的功能,可以很方便地查看分析源代码.   关键词: vim, cscope, ctags, tags   1. 查看vi ...

  8. javaweb基础(12)_session详解

    一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...

  9. fiddler 模拟发送post请求

    打开fiddler,选择在右边的Composer工具栏,打开Parsed选项,然后数据发送协议,例如选择POST, POST右边输入框可以输入访问地址, 下方的输入框可以输入发送的输入操作,例如发送的 ...

  10. Title Case a Sentence-freecodecamp算法题目

    Title Case a Sentence(中单词首字母大写) 要求 确保字符串的每个单词首字母都大写,其余部分小写. 像'the'和'of'这样的连接符同理. 思路 将句子小写化后用.split(& ...