POJ1066:Treasure Hunt——题解
http://poj.org/problem?id=1066
题目大意:给一个由墙围成的正方形,里面有若干墙,每次破墙只能从(当前看到的)墙的中点破,求最少破多少墙才能看到宝藏。
——————————————————————
显然枚举起点然后画一条以终点为端点的线,求线和多少墙相交即可。
但是我不会证明:这里有证明:https://www.cnblogs.com/anrainie/p/4049844.html
然后有该证明我们得到只要起点为这些线的端点即可。
#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef double dl;
const int INF=;
const int N=;
struct point{//既是向量又是点
dl x;
dl y;
}p[*N],ed;
int n;
inline point getmag(point a,point b){
point s;
s.x=b.x-a.x;s.y=b.y-a.y;
return s;
}
inline dl multiX(point a,point b){
return a.x*b.y-b.x*a.y;
}
inline int intersect(point a,point b){
int ans=;
if(a.x==b.x&&a.y==b.y)return ;
for(int i=;i<=n;i++){
dl d1=multiX(getmag(a,p[i]),getmag(a,b))*multiX(getmag(a,p[i+n]),getmag(a,b));
dl d2=multiX(getmag(p[i],a),getmag(p[i],p[i+n]))*multiX(getmag(p[i],b),getmag(p[i],p[i+n]));
if(d1<=&&d2<=)ans++;
}
return ans;
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%lf%lf%lf%lf",&p[i].x,&p[i].y,&p[i+n].x,&p[i+n].y);
}
scanf("%lf%lf",&ed.x,&ed.y);
if(n==){
printf("Number of doors = 1\n");
return ;
}
int ans=INF;
for(int i=;i<=*n;i++){
ans=min(ans,intersect(p[i],ed));
}
printf("Number of doors = %d\n",ans);
return ;
}
POJ1066:Treasure Hunt——题解的更多相关文章
- poj1066 Treasure Hunt【计算几何】
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8192 Accepted: 3376 Des ...
- POJ1066 Treasure Hunt
嘟嘟嘟 题意看题中的图就行:问你从给定的点出发最少需要穿过几条线段才能从正方形中出去(边界也算). 因为\(n\)很小,可以考虑比较暴力的做法.枚举在边界中的哪一个点离开的.也就是枚举四周的点\((x ...
- Treasure Hunt
Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- zoj 3629 Treasure Hunt IV 打表找规律
H - Treasure Hunt IV Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- ZOJ 3626 Treasure Hunt I 树上DP
E - Treasure Hunt I Time Limit:2000MS Memory Limit:65536KB Description Akiba is a dangerous country ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1
题目描述 Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and ...
- ZOJ 3626 Treasure Hunt I(树形dp)
Treasure Hunt I Time Limit: 2 Seconds Memory Limit: 65536 KB Akiba is a dangerous country since ...
- zoj Treasure Hunt IV
Treasure Hunt IV Time Limit: 2 Seconds Memory Limit: 65536 KB Alice is exploring the wonderland ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
随机推荐
- 安装wamp后,其显示目录的图标显示不出来
解决办法:wamp的安装目录中,到 wamp\bin\apache\Apache2.2.21\conf \extra下打开httpd-autoindex.conf文件,这里是索引文件图标的配置文件.修 ...
- thinkphp5使用workerman的定时器定时任务在某一个时间执行
1.首先通过 composer 安装workerman,在thinkphp5完全开发手册的扩展->coposer包->workerman有详细说明: #在项目根目录执行以下指令compos ...
- Java开发工程师(Web方向) - 03.数据库开发 - 第5章.MyBatis
第5章--MyBatis MyBatis入门 Abstract: 数据库框架的工作原理和使用方法(以MyBatis为例) 面向对象的世界与关系型数据库的鸿沟: 面向对象世界中的数据是对象: 关系型数据 ...
- [JSON].set(keyPath, value)
语法:[JSON].set( keyPath, value ) 返回:[True | False] 说明:设置键值 参数: keyPath [keyPath 必需] 键名路径字符串 value ...
- JAVA基础学习之路(六)数组与方法参数的传递
通常,向方法中传递的都是基本数据类型,而向方法中传递数组时,就需要考虑内存的分配 public class test2 { public static void main(String args[]) ...
- LeetCode 445——两数相加 II
1. 题目 2. 解答 2.1 方法一 在 LeetCode 206--反转链表 和 LeetCode 2--两数相加 的基础上,先对两个链表进行反转,然后求出和后再进行反转即可. /** * Def ...
- WCF服务库创建-20140919
1. 创建wcf服务库 2. 宿主到web程序上 // 宿主wcf服务库 RouteTable.Routes.Add(new ServiceRoute("ctserver.dll" ...
- 2.hadoop基本配置,本地模式,伪分布式搭建
2. Hadoop三种集群方式 1. 三种集群方式 本地模式 hdfs dfs -ls / 不需要启动任何进程 伪分布式 所有进程跑在一个机器上 完全分布式 每个机器运行不同的进程 2. 服务器基本配 ...
- 每周psp-第五周
PSP表格: 类别 任务 开始时间 结束时间 中断时间 delta时间 开会 scrum立会 10.13下午6:04 10.13下午6:34 0 30 开会 scrum立会 10.14下午6:02 1 ...
- C语言 命令行参数 函数指针 gdb调试
. 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21551397 | http://www.hanshul ...