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. Redis系列八 使用Jedis

    使用Jedis jar操作Redis 1.配置redis.conf文件,修改 2.建java工程,加入 jedis jar包 3.代码示例: package com.ntjr.redis; impor ...

  2. unity share current game screen

    using UnityEngine; using System.Collections; using UnityEngine.UI; using System.IO; public class Tak ...

  3. 60帧的丝般顺畅 - QQ飞车手游优化点滴

    WeTest 导读 加入项目组的这段时间主要是承担性能优化这块的工作,同时也会去实现一些场景材质.特效材质以及工具.今天就性能优化这块分享一下个人的经验. 设备等级划分 设备等级划分是一切优化,LOD ...

  4. mysql新手入门随笔4

    40.子查询:出现在其他SQL语句里的SELECT语句 例如:SELECT sname,mark FROM student WHERE mark = (SELECT max(mark) FROM st ...

  5. 【WXS全局对象】consloe

    consloe对象 方法: 原型:console.log( [String] ) 说明:用于在 console 窗口输出信息,一般用于程序调试使用示例: console.log支持arguments类 ...

  6. node事件循环

    Node.js 是单进程单线程应用程序,但是通过事件和回调支持并发,所以性能非常高. Node.js 的每一个 API 都是异步的,并作为一个独立线程运行,使用异步函数调用,并处理并发. Node.j ...

  7. Python3 小工具-ARP扫描

    from scapy.all import * import optparse import threading import os def scan(ipt): pkt=Ether(dst='ff: ...

  8. Linux 静态和动态添加路由

    (一)静态添加 1/5 首先让我们查看当前机器的路由表,执行如下命令:route -n [root@vnode33 network-scripts]# route -n Kernel IP routi ...

  9. 【树莓派 Raspberry-Pi 】用Windows远程桌面连接树莓派的方法【转】

    树莓派DIY笔记之前有介绍过用VNC连接到树莓派的方法.在Windows下,当然还是自带的远程桌面更便捷.如果不想用VNC,利用远程桌面(mstsc.exe)连接树莓派,如何实现? 只需要在raspb ...

  10. jquery中的$(document).ready()、JavaScript中的window.onload()以及body中的onload()、DomContentLoaded()区别

    $().ready().$(handler).$(document).ready(handler)均不是原生JS中的,都是jQuery中封装的方法.这些事件在当页面的dom节点加载完毕后就执行,无需等 ...