Treasure Hunt
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6328   Accepted: 2627

Description

Archeologists from the Antiquities and Curios Museum (ACM) have flown to Egypt to examine the great pyramid of Key-Ops. Using state-of-the-art technology they are able to determine that the lower floor of the pyramid is constructed from a series of straightline walls, which intersect to form numerous enclosed chambers. Currently, no doors exist to allow access to any chamber. This state-of-the-art technology has also pinpointed the location of the treasure room. What these dedicated (and greedy) archeologists want to do is blast doors through the walls to get to the treasure room. However, to minimize the damage to the artwork in the intervening chambers (and stay under their government grant for dynamite) they want to blast through the minimum number of doors. For structural integrity purposes, doors should only be blasted at the midpoint of the wall of the room being entered. You are to write a program which determines this minimum number of doors.
An example is shown below:

Input

The
input will consist of one case. The first line will be an integer n (0
<= n <= 30) specifying number of interior walls, followed by n
lines containing integer endpoints of each wall x1 y1 x2 y2 . The 4
enclosing walls of the pyramid have fixed endpoints at (0,0); (0,100);
(100,100) and (100,0) and are not included in the list of walls. The
interior walls always span from one exterior wall to another exterior
wall and are arranged such that no more than two walls intersect at any
point. You may assume that no two given walls coincide. After the
listing of the interior walls there will be one final line containing
the floating point coordinates of the treasure in the treasure room
(guaranteed not to lie on a wall).

Output

Print a single line listing the minimum number of doors which need to be created, in the format shown below.

Sample Input

7
20 0 37 100
40 0 76 100
85 0 0 75
100 90 0 90
0 71 100 61
0 14 100 38
100 47 47 100
54.5 55.4

Sample Output

Number of doors = 2 
题意:求从矩形上到宝藏点需要破开的最少的门。。相交点算两张门。
题解:本人方法是,,直接全部枚举,碰到和矩形边相交的直线直接跳过。。最后记得+1
///判断直线与线段相交
///做法:枚举每两个端点,要是存在一条直线经过这两个端点并且和所有线段相交就OK,但是不能为重合点.
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ;
const double eps = 1e-;
struct Point
{
double x,y;
};
struct Line
{
Point a,b;
} line[N];
int n;
double cross(Point a,Point b,Point c){
return (a.x-c.x)*(b.y-c.y)-(b.x-c.x)*(a.y-c.y);
}
bool isCross(Point a, Point b, Point c, Point d)
{
if (cross(c, b, a)*cross(b, d, a)<)return false;
if (cross(a, d, c)*cross(d, b, c)<)return false;
return true;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int 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 e;
scanf("%lf%lf",&e.x,&e.y);
int mi = ;
int cnt;
for(int j=; j<=; j++)
{
for(int i=; i<=; i++)
{
Point s;
if(j==) s.x=i,s.y=;
if(j==) s.x=,s.y=i;
if(j==) s.x=,s.y = i;
if(j==) s.x=i,s.y=;
cnt=;
for(int k=; k<n; k++){
if(fabs(s.x-line[k].a.x)<eps&&fabs(s.y-line[k].a.y)<eps) continue;
if(fabs(s.x-line[k].b.x)<eps&&fabs(s.y-line[k].b.y)<eps) continue;
if(isCross(s,e,line[k].a,line[k].b)){
cnt++;
}
}
//printf("%d\n",cnt);
if(mi>cnt) mi = cnt;
}
}
if(n==) printf("Number of doors = 1\n");
else printf("Number of doors = %d\n",mi+);
} return ;
}

poj 1066(枚举+线段相交)的更多相关文章

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

    题目大意:在一个正方形的迷宫里有一些交错墙,墙的两端都在迷宫的边缘墙上面,现在得知迷宫的某个位置有一个宝藏,所以需要砸开墙来获取宝藏(只能砸一段墙的中点),问最少要砸开几面墙.   分析:这个题意刚开 ...

  2. POJ 1408 Fishnet【枚举+线段相交+叉积求面积】

    题目: http://poj.org/problem?id=1408 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  3. POJ 1039 Pipe 枚举线段相交

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9493   Accepted: 2877 Description ...

  4. [poj 1039]Pipes[线段相交求交点]

    题意: 无反射不透明管子, 问从入口射入的所有光线最远能到达的横坐标. 贯穿也可. 思路: 枚举每一组经过 up [ i ] 和 down [ j ] 的直线, 计算最远点. 因为无法按照光线生成的方 ...

  5. C - Segments POJ - 3304 (判断线段相交)

    题目链接:https://vjudge.net/contest/276358#problem/C 题目大意:给你n条线段,问你是否存在一条线段使得所有的线段在这条直线的投影至少具有一个交点? 具体思路 ...

  6. poj 2653 (线段相交判断)

    http://poj.org/problem?id=2653 Pick-up sticks Time Limit: 3000MS   Memory Limit: 65536K Total Submis ...

  7. POJ 1039 Pipe | 线段相交

    题目: 给一个管子,有很多转弯处,问从管口的射线射进去最长能射到多远 题解: 根据黑书,可以证明的是这条光线一定经过了一个上顶点和下顶点 所以我们枚举每对上下顶点就可以了 #include<cs ...

  8. poj 1410 Intersection 线段相交

    题目链接 题意 判断线段和矩形是否有交点(矩形的范围是四条边及内部). 思路 判断线段和矩形的四条边有无交点 && 线段是否在矩形内. 注意第二个条件. Code #include & ...

  9. POJ 3449 /// 判断线段相交

    题目大意: 给出多个多边形及其编号 按编号顺序输出每个多边形与其相交的其他多边形编号 注意一个两个多个的不同输出 将每个多边形处理成多条边 然后去判断与其他多边形的边是否相交 计算正方形另外两点的方法 ...

随机推荐

  1. 《学习OpenCV》课后习题解答8

    题目:(P126) 本章完整讲述了基本的输入/输出编程以及OpenCV的数据结构.下面的练习是基于前面的知识做一些应用,为后面大程序的实现提供帮助. a.创建一个程序实现以下功能:(1)从视频文件中读 ...

  2. servletContex.getRealPath 获取的是拼接后的地址 是虚假的

    servletContex.getRealPath 获取的是拼接后的地址 是虚假的

  3. [COGS 2089.] 平凡的测试数据 带权并查集

    差点就撸上LCT了....... 带权并查集就是在并查集的基础上稍作修改,我的用穿址实现的有人用记录原父亲来实现. #include<cstdio> #define N 300010 us ...

  4. vector 进阶

    http://classfoo.com/ccby/article/jnevK #include <iostream> #include <vector> #include &l ...

  5. 整理一些JavaScript时间处理扩展函数

    在JavaScript中,时间处理是经常需要用到的.最近想要慢慢建立自己的代码库,整理了几个之前用到的js处理时间的函数,发出来跟大家分享一下,以后的使用中会不断增加和修改代码库. 把字符串转换为日期 ...

  6. Codeforces 931.D Peculiar apple-tree

    D. Peculiar apple-tree time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. android studio的弹出层

    <activity android:name=".SecondActivity" android:theme="@style/Theme.AppCompat.Dia ...

  8. TOM的show_space

    show_space查看对像数据块的空闲情况 CREATE OR REPLACE PROCEDURE show_space(p_segname IN VARCHAR2, p_owner IN VARC ...

  9. 设置eclipse控制台上的信息输入到某个文件

    转摘自:http://binary.duapp.com/2013/09/1511.html Run->Run Configurations->Common->File

  10. [Python]简单的外星人入侵游戏

    alien_invasion.py: import sys import pygame from setting import Settings from ship import Ship impor ...