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——题解的更多相关文章

  1. poj1066 Treasure Hunt【计算几何】

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8192   Accepted: 3376 Des ...

  2. POJ1066 Treasure Hunt

    嘟嘟嘟 题意看题中的图就行:问你从给定的点出发最少需要穿过几条线段才能从正方形中出去(边界也算). 因为\(n\)很小,可以考虑比较暴力的做法.枚举在边界中的哪一个点离开的.也就是枚举四周的点\((x ...

  3. Treasure Hunt

    Treasure Hunt time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. zoj 3629 Treasure Hunt IV 打表找规律

    H - Treasure Hunt IV Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu ...

  5. ZOJ 3626 Treasure Hunt I 树上DP

    E - Treasure Hunt I Time Limit:2000MS Memory Limit:65536KB Description Akiba is a dangerous country ...

  6. 湖南大学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 ...

  7. ZOJ 3626 Treasure Hunt I(树形dp)

    Treasure Hunt I Time Limit: 2 Seconds      Memory Limit: 65536 KB Akiba is a dangerous country since ...

  8. zoj Treasure Hunt IV

    Treasure Hunt IV Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is exploring the wonderland ...

  9. POJ 1066 Treasure Hunt(线段相交判断)

    Treasure Hunt Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4797   Accepted: 1998 Des ...

随机推荐

  1. 二、StreamAPI

    一.Stream是什么? 是数据通道,用于操作数据源(集合.数组等)所生成的元素序列.集合讲的是数据,流讲的是计算. 注意: Stream不会存储元素. Stream不会改变源对象.相反,他们会返回一 ...

  2. jsp传递参数的四种方法

    1.form表单 2.request.setAttribute();和request.getAttribute(); 3.超链接:<a herf="index.jsp"?a= ...

  3. hackhttp模板的介绍

    hackhttp模板:造福人类 发起get/post/ 发起http原始数据包 漏洞利用:更为快捷放放不安 #hackhttp使用方法hh=hackhttp.hackhttp() code,head, ...

  4. Fiddler使用总结(二)

    在上一篇中介绍了Fiddler的基本使用方法.通过上一篇的操作我们可以直接抓取浏览器的数据包.但在APP测试中,我们需要抓取手机APP上的数据包,应该怎么操作呢? Andriod配置方法: .确保手机 ...

  5. js for循环实例

    1.求1-100的寄数和? //2.奇数求和 var ppt=0 for(var i=1;i<=100;i+=2){ ppt+=i } 2.求1-100的偶数和 var num=0 for(va ...

  6. c字符指针与字符数组的区别

    1.定义 char *pchar;  //定义了指针,没赋值之前不能使用.如果:printf("*pchar:%c\n",*pchar); 出现段错误Segmentation fa ...

  7. Ubuntu—终端命令调整窗口的大小

    1,查看窗口大小 current 1280x768 是我当前电脑的窗口大小,下面提供的是可以修改的窗口大小. $ xrandr 2.修改窗口大小 示例: $ xrandr -s 1024x768

  8. SIG蓝牙mesh笔记3_网络结构

    目录 3. Mesh Networking 3.1 Bearers 承载层 3.2 Network Layer 网络层 3.2.3 Address validity 地址有效性 3.2.4 Netwo ...

  9. Java 单例模式探讨

    以下是我再次研究单例(Java 单例模式缺点)时在网上收集的资料,相信你们看完就对单例完全掌握了 Java单例模式应该是看起来以及用起来简单的一种设计模式,但是就实现方式以及原理来说,也并不浅显哦. ...

  10. Linux下实现Rsync目录同步备份

    需求:对于开发机器做目录的数据备份 测试机IP:192.168.1.100   WEB目录:/bckup/ 下面我将用一台机器来备份上面测试机 /bckup下的所有数据,并实现时时同步 备份机器IP: ...