嘟嘟嘟




题意看题中的图就行:问你从给定的点出发最少需要穿过几条线段才能从正方形中出去(边界也算)。




因为\(n\)很小,可以考虑比较暴力的做法。枚举在边界中的哪一个点离开的。也就是枚举四周的点\((x, y)\),并和起点\((x_0, y_0)\)连成线段,求和多少条线段相交。

但是因为点可以是实数,所以不知道怎么枚举。不过想想就知道,同一个区间中的点是等价的。因此我们只要枚举线段的端点即可。

至于判断线段相交,用叉积实现:对于线段\(AB\)和\(CD\),如果\((\overrightarrow{AB} \times \overrightarrow{AC}) * (\overrightarrow{AB} \times \overrightarrow{AD}) < 0\)且\((\overrightarrow{CD} \times \overrightarrow{CA}) * (\overrightarrow{CD} \times \overrightarrow{CB}) < 0\),则线段\(AB\)和\(CD\)相交。




(别忘了\(n = 0\)的情况……)

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-8;
const int maxn = 50;
inline ll read()
{
ll ans = 0;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < 0) x = -x, putchar('-');
if(x >= 10) write(x / 10);
putchar(x % 10 + '0');
} int n;
struct Vec
{
db x, y;
db operator * (const Vec& oth)const
{
return x * oth.y - oth.x * y;
}
};
struct Point
{
db x, y;
Vec operator - (const Point& oth)const
{
return (Vec){x - oth.x, y - oth.y};
}
}a[maxn], b[maxn], P; int solve(Point A, Point B)
{
Vec AB = B - A;
int ret = 0;
for(int i = 1; i <= n; ++i)
{
Vec AC = a[i] - A, AD = b[i] - A;
Vec CD = b[i] - a[i], CB = B - a[i];
if((AB * AC) * (AB * AD) < -eps && (CD * AC) * (CD * CB) > eps) ret++;
}
return ret;
} int ans = INF; int main()
{
n = read();
for(int i = 1; i <= n; ++i)
a[i].x = read(), a[i].y = read(), b[i].x = read(), b[i].y = read();
scanf("%lf%lf", &P.x, &P.y);
for(int i = 1; i <= n; ++i)
{
ans = min(ans, solve(a[i], P));
ans = min(ans, solve(b[i], P));
}
if(!n) ans = 0;
printf("Number of doors = ");
write(ans + 1), enter;
return 0;
}

POJ1066 Treasure Hunt的更多相关文章

  1. poj1066 Treasure Hunt【计算几何】

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

  2. zoj Treasure Hunt IV

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

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

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

  4. ZOJ3629 Treasure Hunt IV(找到规律,按公式)

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

  5. POJ 1066 Treasure Hunt(相交线段&amp;&amp;更改)

    Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...

  6. Treasure Hunt

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

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

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

  8. ZOJ 3626 Treasure Hunt I 树上DP

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

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

随机推荐

  1. C# AJAXform上传图片

     前台: @{    Layout = null;} <!DOCTYPE html> <html><head>    <meta name="vie ...

  2. HDU 2639(01背包第K大)

    http://acm.hdu.edu.cn/showproblem.php?pid=2639 http://blog.csdn.net/lulipeng_cpp/article/details/758 ...

  3. HDU 2199 (二分法)

    主要思想就是两端逼近,最后得到结果,0MS #include <iostream> #include <cstdlib> #include <cstdio> #in ...

  4. CodeChef SADPAIRS:Chef and Sad Pairs

    vjudge 首先显然要建立圆方树 对于每一种点建立虚树,考虑这一种点贡献,对于虚树上已经有的点就直接算 否则对虚树上的一条边 \((u, v)\),\(u\) 为父亲,假设上面连通块大小为 \(x\ ...

  5. apply的妙用

    有一个很常见的问题"call和apply的区别是什么?",大家都知道答案:它们的区别仅在于接受参数的方式不同,传递给call的第二个参数必须逐个列举出来,而传递给apply的第二个 ...

  6. React+antd 在限制高度内实现滚动显示多个组件(show scrolled components in a limited height with react antd)

    效果: 代码: import React from 'react'; import { Table } from 'antd'; import DatePicker1 from './DatePick ...

  7. is_array判断是否为数组

    if(is_array($arr)){ echo "是数组"; }else{ echo "不是数组"; }

  8. iview动态校验表单,获取值为undefined

    场景:实际代码如下:https://run.iviewui.com/XPofr3YS 原因:在动态校验名称时,没法获取值,请教了大神后,发现原来是自己demo没理清楚 这里的prop="na ...

  9. Android架构设计之插件化、组件化

    如今移动app市场已经是百花齐放,其中有不乏有很多大型公司.巨型公司都是通过app创业发展起来的:app类型更加丰富,有电子商务.有视频.有社交.有工具等等,基本上涵盖了各行各业每个角落,为了更加具有 ...

  10. Android图片处理--缩放

    PS:在开发中我们会遇到一些图片处理问题,比如说缓存图片了.限制图片大小了.查看图片了等.上一篇文章介绍了图片的全景效果查看,今天介绍一个图片缩放,我们如果有时间的话,可以自己写一个属于自己的库,里面 ...