Poj 1066 Treasure Hunt && Nyoj 83 迷宫寻宝(二)判断线段相交
来源:互联网 发布:淘宝女装模特拍摄技巧 编辑:程序博客网 时间:2024/05/16 01:27
题目链接:poj 1066 nyoj 83
题目的意思很是简单,说是有一个四边形的迷宫。某一个位置有个宝物在某一点,迷宫中还有很多的墙。问最少需要凿开多少门才能拿到宝物。
思路:直接枚举所有墙的端点+宝物的位置作为一条线段, 求出与之相交的最少线段数。就是答案。
nyoj Code:
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;const int N = 35;const int INF = 0xffffff;const double eps = 1e-8;struct POINT{ double x, y;};struct LINE{ POINT a, b;}l[N];int n;double cross(POINT o, POINT a, POINT b){ return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);}int Judge(POINT X, POINT Y){ int ans = 0; for(int i = 0; i < n; i ++){// printf("cross = %.2lf\n", cross(X, l[i].a, l[i].b) * cross(Y, l[i].a, l[i].b)); if(cross(X, l[i].a, l[i].b) * cross(Y, l[i].a, l[i].b) < -eps) ans ++; }// printf("ans = %d\n", ans); return ans;}int main(){ int T; scanf("%d", &T); while(T --){ scanf("%d", &n); if(n == 0){ puts("1"); continue; } for(int i = 0; i < n; i ++){ scanf("%lf %lf %lf %lf", &l[i].a.x, &l[i].a.y, &l[i].b.x, &l[i].b.y); } POINT d; scanf("%lf %lf", &d.x, &d.y); int ans = INF; for(int i = 0; i < n; i++){ ans = min(Judge(l[i].a, d), ans); ans = min(Judge(l[i].b, d), ans);// printf("ans = %d\n", ans); } printf("%d\n", ans + 1); } return 0;}
Poj的数据较强。
需要注意的点:
1.即使墙的数目为0,也需要知道宝物的位置。
2.Poj这道题是输入一组数据,但是好像是多线程。
3.判断相交直接叉积小于0就好。
0 0
- Poj 1066 Treasure Hunt && Nyoj 83 迷宫寻宝(二)判断线段相交
- poj 1066 Treasure Hunt(判断线段相交)
- POJ 1066 Treasure Hunt(线段相交判断)
- POJ 1066 Treasure Hunt(线段相交判断)
- poj 1066 Treasure Hunt(判断线段相交)
- poj 1066 Treasure Hunt(判断线段相交)
- poj 1066 Treasure Hunt(判断线段相交)
- POJ 1066 Treasure Hunt (线段相交)
- nyoj 83 迷宫寻宝(二)(线段相交问题)
- POJ 1066 Treasure Hunt 判断两线段是否相交
- POJ 1066 Treasure Hunt (判断线段相交个数)
- 1066 Treasure Hunt (判断线段相交)
- POJ 1066 Treasure Hunt --几何,线段相交
- POJ 1066 Treasure Hunt 【线段相交】
- POJ 1066 Treasure Hunt 判断线段相交(求交点个数)
- POJ 1066 Treasure Hunt(线段相交&&转换)
- POJ 1066 Treasure Hunt(转化线段相交)
- POJ 1066 Treasure Hunt (思维、线段相交)
- cloudera mamager中配置hive加载自定义的jar包
- GOLANG Http Counter
- 上海汉枫电子推出能“听”会“说”的物联网Wi-Fi模块
- DEBUG方法
- 澳洲ICT专业人数逐年锐减,威胁价值达1000亿元
- Poj 1066 Treasure Hunt && Nyoj 83 迷宫寻宝(二)判断线段相交
- 写宏遇到的问题:warning: backslash and newline separated by space
- MFC读取xml文件
- opencv 数字图像直方图
- 免费pdf转换成ppt转换器下载
- 来者如临高山,往者以观逝水--天猫品牌推荐算法比赛总结
- hdu 1083 Courses 二分图最大匹配
- 哈佛经济学家关于工作效率的意外发现
- hdu1026 Ignatius and the Princess I