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 ;
}

最新文章

  1. Linux下的压缩和解压缩命令——jar
  2. js练习-控制div属性
  3. ID
  4. CentOS 6.8内核版本升级(升级至3.10)(转)
  5. 如何使用Retrofit获取服务器返回来的JSON字符串
  6. ubuntu14.04编译mono源码(有坑...)
  7. 微软 Build 2014开发者大会干货整理-1
  8. 养成一个SQL好习惯带来一笔大财富
  9. WordPress插件制作笔记(一)---First Plugins Demo
  10. C# 多态理论基础
  11. java参数传值方式
  12. java http post/get 服务端和客户端实现json传输
  13. kubernetes in action - Pods
  14. Coursera, Deep Learning 1, Neural Networks and Deep Learning - week4, Deep Neural Networks
  15. 图标网站,IcoMoon,自己动手做一个 font
  16. EF5+MVC4系列(8) ActionResult的返回值
  17. Git 学习(七)标签管理
  18. Dlib简介及在windows7 vs2013编译过程
  19. bzoj 1131 简单树形dp
  20. URL转发

热门文章

  1. 软工实践 - 第二十四次作业 Beta 冲刺(2/7)
  2. JDK源码分析 – Integer
  3. iOS版微信开发小结(微信支付,APP跳转微信公众号)
  4. Mac OSX 10.11安装Jekyll
  5. 【bzoj3052】[wc2013]糖果公园 带修改树上莫队
  6. P2730 魔板 Magic Squares
  7. 洛谷 P1415 拆分数列 解题报告
  8. WordPress后台edit-tags.php里无限栏目分类实现
  9. Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C (用map 超时)
  10. Substrings Sort string 基本操作