poj 1066 Treasure Hunt (未完)
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define eps 1e-8
#define zero(x) (((x)>0 ? (x):(-x))<eps)
#define INF 0x3f3f3f3f
struct Point
{
double x,y;
}tre,point[],tp;
struct Line
{
Point a,b;
}line[];
double xmult(Point p1,Point p2,Point p0)
{
return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double dmult(Point p1,Point p2,Point p0)
{
return (p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);
}
int dis(Point p1,Point p2)
{
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
int cmp(const void *a,const void *b)
{
Point *c=(Point *)a;
Point *d=(Point *)b;
int k=xmult(point[],*c,*d);
if(k<||!k&&dis(point[],*c)>dis(point[],*d))
return ;
return -;
}
int main()
{
int i,j,n,ans,tmp;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%lf%lf%lf%lf",&line[i].a.x,&line[i].a.y,&line[i].b.x,&line[i].b.y);
point[*i]=line[i].a;
point[*i+]=line[i].b;
}
scanf("%lf%lf",&tre.x,&tre.y); int m=n;
point[m].x=point[m++].y=;
point[m].x=;point[m++].y=;
point[m].x=point[m++].y=;
point[m].x=;point[m++].y=; qsort(point+,m-,sizeof(Point),cmp);
point[m++]=point[]; ans=INF;
for(i=;i<m-;i++)
{
tmp=;
//tp.x=(point[i].x+point[i+1].x)/2;
//tp.y=(point[i].y+point[i+1].y)/2;
tp=point[i];
for(j=;j<n;j++)
{
if(xmult(tre,line[j].a,line[j].b)*xmult(tp,line[j].a,line[j].b)<-eps&&
xmult(line[j].a,tre,tp)*xmult(line[j].b,tre,tp)<-eps)tmp++;
}
if(tmp<ans)ans=tmp;
}
printf("Number of doors = %d\n",ans-);
return ;
}
poj 1066 Treasure Hunt (未完)的更多相关文章
- poj 1066 Treasure Hunt (Geometry + BFS)
1066 -- Treasure Hunt 题意是,在一个金字塔中有一个宝藏,金字塔里面有很多的墙,要穿过墙壁才能进入到宝藏所在的地方.可是因为某些原因,只能在两个墙壁的交点连线的中点穿过墙壁.问最少 ...
- POJ 1066 Treasure Hunt(线段相交判断)
Treasure Hunt Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4797 Accepted: 1998 Des ...
- POJ 1066 Treasure Hunt(相交线段&&更改)
Treasure Hunt 大意:在一个矩形区域内.有n条线段,线段的端点是在矩形边上的,有一个特殊点,问从这个点到矩形边的最少经过的线段条数最少的书目,穿越仅仅能在中点穿越. 思路:须要巧妙的转换一 ...
- POJ 1066 - Treasure Hunt - [枚举+判断线段相交]
题目链接:http://poj.org/problem?id=1066 Time Limit: 1000MS Memory Limit: 10000K Description Archeologist ...
- poj 1066 Treasure Hunt
http://poj.org/problem?id=1066 #include <cstdio> #include <cstring> #include <cmath&g ...
- POJ 1066 Treasure Hunt [想法题]
题目链接: http://poj.org/problem?id=1066 --------------------------------------------------------------- ...
- POJ 1066 Treasure Hunt (线段相交)
题意:给你一个100*100的正方形,再给你n条线(墙),保证线段一定在正方形内且端点在正方形边界(外墙),最后给你一个正方形内的点(保证不再墙上) 告诉你墙之间(包括外墙)围成了一些小房间,在小房间 ...
- POJ 1066 Treasure Hunt【线段相交】
思路:枚举四边墙的门的中点,与终点连成一条线段,判断与其相交的线段的个数.最小的加一即为答案. 我是傻逼,一个数组越界调了两个小时. #include<stdio.h> #include& ...
- POJ 1066 Treasure Hunt --几何,线段相交
题意: 正方形的房子,给一些墙,墙在区域内是封闭的,给你人的坐标,每穿过一道墙需要一把钥匙,问走出正方形需要多少把钥匙. 解法: 因为墙是封闭的,所以绕路也不会减少通过的墙的个数,还不如不绕路走直线, ...
随机推荐
- 算法题:求一个序列S中所有包含T的子序列(distinct sub sequence)
题: 给定一个序列S以及它的一个子序列T,求S的所有包含T的子序列.例: S = [1, 2, 3, 2, 4] T = [1, 2, 4] 则S的所有包含T的子序列为: [1, 2, 3, 2, 4 ...
- python 发红包
import random li = [] def fahongbao(money,num=6): if money > 0 and num != 1: n = round(random.uni ...
- struts2学习(6)自定义拦截器-登录验证拦截器
需求:对登录进行验证,用户名cy 密码123456才能登录进去: 登录进去后,将用户存在session中: 其他链接要来访问(除了登录链接),首先验证是否登录,对这个进行拦截: com.cy.mod ...
- SpringMVC之八:基于SpringMVC拦截器和注解实现controller中访问权限控制
SpringMVC的拦截器HandlerInterceptorAdapter对应提供了三个preHandle,postHandle,afterCompletion方法. preHandle在业务处理器 ...
- 北京师范大学第十六届程序设计竞赛决赛 C萌萌哒身高差
链接:https://www.nowcoder.com/acm/contest/117/C来源:牛客网 萌萌哒身高差 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他 ...
- c# 判断文件是否已使用
string path = Server.MapPath(" PDFs"); bool tfOpenTemp= IsFileInUse(path + " /Doc1.pd ...
- 如何混编c++
1. 如何混编c++ 用 Xcode4 创建一个 工程,如果在任意一个文件AAA.h的头部加入 #include<string> using namespace std; 编译运行, ...
- Django xadmin的使用 (二)
上一篇中我们基本完成了xadmin的配置,但是要进行正式使用还需要更多细致的配置. 1.页面显示中文 settings.py中配置(这个和django自带的admin配置一样) # LANGUAGE_ ...
- IOS省电
1.关闭定位 2.关闭后台刷新
- ffmpeg打开视频解码器失败:Could not find codec parameters for stream 0 (Video: h264): unspecified size
在使用ffmpeg进行拉流分离音视频数据再解码播放操作的时候: 有时候经常会报错: Could not find codec parameters for stream 0 (Video: h264) ...