poj 1066 Treasure Hunt
题目的意思就是从边界某个点出发到目标点问最少要和多少条线段相交。
枚举边界上的点判断就行了。
注意n=0时ans=1
CODE:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define DOR(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define oo 1e6
#define eps 1e-8
#define nMax 1000
#define pb push_back
#define bug puts("OOOOh.....");
#define zero(x) (((x)>0?(x):-(x))<eps)int dcmp(double x){if(fabs(x)<eps) return 0;return x>0?1:-1;
}
struct point {double x,y;point(double x=0,double y=0): x(x),y(y) {}void make(double _x,double _y) {x=_x;y=_y;}void read(){ scanf("%lf%lf",&x,&y); }double len(){ return sqrt(x*x+y*y); }friend point operator -(point const& u,point const& v) {return point(u.x-v.x,u.y-v.y);}friend point operator +(point const& u,point const& v) {return point(u.x+v.x,u.y+v.y);}friend double operator *(point const& u,point const& v) {return u.x*v.y-u.y*v.x;}friend double operator ^(point const& u,point const& v) {return u.x*v.x+u.y*v.y;}friend point operator *(double const& k,point const& v) {return point(k*v.x,k*v.y);}friend point operator /(point const& u,double const& k){return point(u.x/k,u.y/k);}friend bool operator < (point const& u,point const& v) {if(dcmp(u.x-v.x) == 0) return dcmp(u.y-v.y)<0;return dcmp(u.x-v.x)<0;}friend bool operator == (point const& u,point const& v) {return (dcmp(u.x-v.x) == 0) && dcmp(u.y-v.y)==0;}friend int dots_online(point,point,point);
};
int dots_online(point a,point b,point c){ return dcmp((a-c)*(b-c))==0; }
typedef struct line{point a,b;line() {}line(point a,point b): a(a),b(b) {}void make(point _a,point _b) {a=_a;b=_b;}void read() { a.read(),b.read(); }friend int intersection(line,line);
} segment;
int dot_in_line(point p,line l){return dcmp((l.a-p)*(p-l.b))==0 && dcmp((l.a-p)^(p-l.b))>=0;
}
int sameside(point a,point b,line l){return dcmp((l.a-a)*(a-l.b)) * dcmp((l.a-b)*(b-l.b)) > 0;
}
int intersection(line u,line v){if(dots_online(u.a,u.b,v.a) && dots_online(u.a,u.b,v.b))return dot_in_line(u.a,v) || dot_in_line(u.b,v) || dot_in_line(v.a,u) || dot_in_line(v.a,u);elsereturn !sameside(u.a,u.b,v) && !sameside(v.a,v.b,u);
}
int n,cnt;
point p,p1,p2;
line l[nMax];
vector<point> s[4];
int g[nMax][nMax];int main(){
#ifndef ONLINE_JUDGEfreopen("input.txt","r",stdin);
#endifscanf("%d",&n);for(int i=0;i<n;i++) {p1.read(),p2.read();l[i].make(p1,p2);}p.read();int ans = oo,f;if(n==0) ans=0;for(int i=0;i<n;i++) {segment s(p,l[i].a);f=0;for(int k=0;k<n;k++) if(!dot_in_line(s.b,l[k]) && intersection(s,l[k])) f++;if(ans>f) ans =f;s.b=l[i].b;f=0;for(int k=0;k<n;k++) if(!dot_in_line(s.b,l[k]) && intersection(s,l[k])) f++;ans = min(ans,f);}printf("Number of doors = %d\n",ans+1);return 0;
}
poj 1066 Treasure Hunt相关推荐
- POJ 1066 Treasure Hunt(计算几何)
题意:给出一个100*100的正方形区域,通过若干连接区域边界的线段将正方形区域分割为多个不规则多边形小区域,然后给出宝藏位置,要求从区域外部开辟到宝藏所在位置的一条路径,使得开辟路径所需要打通的墙壁 ...
- POJ 1066 Treasure Hunt 解题报告
这道题的大概意思就是在一座金字塔的底部,有一个宝藏,但是底部这一层里面有很多纵横交错的墙,而宝藏就在其中一个由这些墙构成的房间里面.每面墙的两头都在金字塔最外面的四周的墙上.然后需要在每面墙的中间开一 ...
- POJ 1066 Treasure
2次AC.只需注意相同端点不用算通过一面墙,最后加上1即可. // // main.cpp // Richard // // Created by 邵金杰 on 16/8/8. // Copyrigh ...
- poj 2594 Treasure Exploration
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6284 Accepted: 2 ...
- poj 2594 Treasure Exploration 最小路径覆盖
题目链接:http://poj.org/problem?id=2594 建图很重要!!! 大致题意: 给出一个由n个顶点m条边组成的有向无环图.求最少可以同时存在多少路径,使得这些路径可以覆盖所有的点 ...
- Python游戏编程(七)Sonar Treasure Hunt
这里将介绍一个采用声纳寻找宝藏的游戏. 首先来了解一下这个游戏涉及到一些概念,并且介绍这个游戏是如何玩的. 目录 (一)游戏说明 (二)导入模块 (三)getNewBoard(): (四)drawBo ...
- POJ 2594 Treasure Exploration (可相交最小路径覆盖)
题意 给你张无环有向图,问至少多少条路径能够覆盖该图的所有顶点--并且,这些路径可以有交叉. 思路 不是裸的最小路径覆盖,正常的最小路径覆盖中两个人走的路径不能有重复的点,而本题可以重复. 当然我们仍 ...
- POJ - 2594 Treasure Exploration(最小路径覆盖-二分图最大匹配+传递闭包)
题目链接:点击查看 题目大意:给出一个有向图,现在需要让最少的机器人沿着图遍历所有点,求出最少需要机器人的数量,注意每个点可以重复遍历 题目分析:因为要遍历所有点,所以还是变成了二分图的最小路径覆盖问 ...
- zoj 3629 Treasure Hunt IV
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4775 看yh大佬的课件的时候看到这题找规律的题,于是我就做了一下.原本我还想在 ...
最新文章
- 腾讯布局移动应用商店 总下载量累计达40亿次
- 使用git提交到github,每次都要输入用户名和密码的解决方法
- Odoo(OpenERP)配置文件详解
- LDAP 查询基本知识
- android xml 未能解析文件,Android Studio中“无法解析符号R”
- OpenI部署二——转载
- 如何将数据仓库从 AWS Redshift 迁移到阿里云 AnalyticDB for PostgreSQL
- 《Introduction to Computing Systems: From bits and gates to C and beyond》
- C++工作笔记-仿大佬“容器”风格
- 门前异动监控、AI 人脸识别!360 发布新型智能门铃
- Win7电脑蓝屏代码大全
- 史上最简单的LSTM文本分类实现:搜狗新闻文本分类(附代码)
- Android Studio 开发实践——简易版音游APP(一)
- 你装陈桥(五笔)啦吗,这是什么...!(qcssb19.exe)
- 搭建外网能访问的web服务器
- CLM陆面过程模式实践技术应用
- 苏轼:醉笑陪君三万场 不诉离殇
- 匈牙利为庆贺第17届奥运会而发行的纪念邮票
- 如何仿照OSINT模式进行机密信息的收集与发掘
- 《闲扯Redis九》Redis五种数据类型之Set型
热门文章
- 腾讯云搭建Cpolar内网穿透
- ATEC | 蚂蚁金服技术出海,如何让人人享有平等的金融服务?
- 意大利牙膏重大突破发明!1分钟让牙齿“再生”,告别敏感疼痛,牙龈萎缩,70岁也能满口好牙...
- (计算机组成原理)RISC与CISC的区别
- [wp7游戏]角色扮演类游戏~~集合贴~~
- 好嗨游戏:20款史上最佳的MMORPG游戏,看看有没有你知道的?
- 【CVPR2020】Detection in Crowded Scenes One Proposal Multiple Predictions 翻译
- mysql修改工资字段_基于Linux的MySQL操作实例(修改表结构,MySQL索引,MySQL数据引擎)...
- CSP 2021 复赛游记
- 蒂特ft232_芯片资料-FT232.pdf