TOJ1017: Tour Guide
描述
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
提示
A: We have constructed the test cases such that it does not matter.
题目来源
这个题目最简洁的想法就是去枚举接哪些人的,也就是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的更多相关文章
- 使用TCPDF插件生成pdf以及pdf的中文处理
目录(?)[+] 多种多样的pdf开发库 WKHTMLTOPDF 2FPDF 3TCPDF 中文问题 做了这么多年项目,以前只是在别人的项目中了解过PHP生成pdf文件,知道并不难,但是涉及到了p ...
- express-17 持久化
简介 所有网站和Web应用程序(除了最简单的)都需要某种持久化方式,即某种比易失性内存更持久的数据存储方式,这样当遇到服务器宕机.断电.升级和迁移等情况时数据才能保存下来. 文件系统持久化 实现持久化 ...
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- 每日英语:Secrets Of Effective Office Humor
Margot Carmichael Lester loves making good-natured jokes at work. As owner of The Word Factory, a Ca ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- 干货分享:深度解析Supplement Essay写作
今天Hotessay小编给同学们介绍下附加文书的创作思路.因为附加文书基本上都是短essay,所以简洁才是硬道理! 通常,我们可以把美国大学的附加文书分为以下几类: 1.Tell us about y ...
- The Definitive C++ Book Guide and List
学习c++的书单 转自 http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list Beginner ...
- 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 ...
- User guide for Netty 4.x
Table of Contents Preface The Solution Getting Started Before Getting Started Writing a Discard Serv ...
随机推荐
- ERwin DM Reverse Engineer 逆向工程介绍
介绍内容:利用ERwin DM进行对本地 Oracle 数据库的逆向工程 ERwin DM Version:7.3 ERwin DM 提供两种方式的逆向工程方法,分别是基于脚本文件和基于数据库. 下面 ...
- c# winform 关于DataGridView的一些操作
转自:http://heisetoufa.iteye.com/blog/405317 设置字段名 设置字段值 设定单元格表示 Error图标 设定当前单元格 取得当前单元格内容 取得当前单元格的列 I ...
- 洛谷 P2176 [USACO14FEB]路障Roadblock
题目描述 每天早晨,FJ从家中穿过农场走到牛棚.农场由 N 块农田组成,农田通过 M 条双向道路连接,每条路有一定长度.FJ 的房子在 1 号田,牛棚在 N 号田.没有两块田被多条道路连接,以适当的路 ...
- 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector
题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her s ...
- UVA 11992 Fast Matrix Operations (降维)
题意:对一个矩阵进行子矩阵操作. 元素最多有1e6个,树套树不好开(我不会),把二维坐标化成一维的,一个子矩阵操作分解成多条线段的操作. 一次操作的复杂度是RlogC,很容易找到极端的数据(OJ上实测 ...
- php循环a-z字母表
ord — 返回字符的 ASCII 码值 说明 int ord ( string $string ) 返回字符串 string 第一个字符的 ASCII 码值. 该函数是 chr() 的互补函数. ...
- 使用ErrorProvider组件验证文本框输入
实现效果: 知识运用: ErrorProvider组件的BlinkStyle属性 //指示错误图标的闪烁时间 public ErrorBlinkStyle BlinkStyle{ get;set; } ...
- x86,x64,i386,i686
x64其实就是64位, x86其实就是32位. 1. i386 适用于intel和AMD所有32位的cpu.以及via采用X86架构的32的cpu. intel平台包括8086,80286,80386 ...
- C#动态数组ArrayList
在C#中,如果需要数组的长度和元素的个数随着程序的运行不断改变,就可以使用ArrayList类,该类是一个可以动态增减成员的数组. 一.ArrayList类的常用属性和方法 1. ArrayList类 ...
- oracle centos 重启后报错ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
oracle centos 重启后报错ORA-12514, TNS:listener does not currently know of service requested in connect d ...