【HDOJ】1756 Cupid's Arrow
图论,点在多边形内部的判定。
/* 1756 */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 const double eps = 1e-;
const int maxn = ; int dcmp(double x) {
if (fabs(x) < eps) return ;
return x< ? -:;
} typedef struct Point {
double x, y; Point() {} Point(double x_, double y_):
x(x_), y(y_) {}
} Point; Point poly[maxn];
int n; Point operator-(Point A, Point B) {
return Point(A.x-B.x, A.y-B.y);
} double Dot(Point A, Point B) {
return A.x*B.x + A.y*B.y;
} double Cross(Point A, Point B) {
return A.x*B.y - A.y*B.x;
} bool OnSegment(Point P, Point A, Point B) {
return dcmp(Cross(A-P, B-P))== && dcmp(Dot(A-P, B-P))<=;
} bool isPointInPolygon(Point p, Point *poly) {
int wn = ; rep(i, , n) {
if (OnSegment(p, poly[i], poly[(i+)%n]))
return true;
int k = dcmp(Cross(poly[(i+)%n]-poly[i], p-poly[i]));
int d1 = dcmp(poly[i].y - p.y);
int d2 = dcmp(poly[(i+)%n].y - p.y); if (k> && d1<= && d2>) ++wn;
if (k< && d2<= && d1>) --wn;
} return wn!=;
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int m;
bool flag;
Point p; while (scanf("%d",&n) != EOF) {
rep(i, , n)
scanf("%lf %lf", &poly[i].x, &poly[i].y);
scanf("%d", &m);
while (m--) {
scanf("%lf %lf", &p.x, &p.y);
flag = isPointInPolygon(p, poly);
puts(flag ? "Yes":"No");
}
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
【HDOJ】1756 Cupid's Arrow的更多相关文章
- HDU 1756 Cupid's Arrow 判断点在多边形的内部
Cupid's Arrow Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 1756:Cupid's Arrow(计算几何,判断点在多边形内)
Cupid's Arrow Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 1756 Cupid's Arrow 计算几何 判断一个点是否在多边形内
LINK:Cupid's Arrow 前置函数 atan2 返回一个向量的幅角.范围为[Pi,-Pi) 值得注意的是 返回的是 相对于x轴正半轴的辐角. 而判断一个点是否在一个多边形内 通常有三种方法 ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
随机推荐
- Objective-C 学习笔记(Day 3,下)
------------------------------------------- 封装概念及其原理 一个Gun类的例子来详细说明这一环节: #import <Foundation/Foun ...
- C# 高精度乘法 支持小数(待优化)
将N*N乘法转化为(N*n1)+(N*n2)....(N*nn) 乘完后在补充小数点 public static char[] Quadrature(string a, string b) { ] { ...
- XML, XPath, Xslt及解析/Parse
XML及解析/Parse "Programming with libxml2 is like the thrilling embrace of an exotic stranger.&quo ...
- OpenJudge 2694 逆波兰表达式
1.链接地址: http://bailian.openjudge.cn/practice/2694/ 2.题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 逆波兰表达式是一种把运算 ...
- SSD论文优秀句子
1. Nonvolatile memory(e.g., Phase Change Memory) blurs the boundary between memory and storage and i ...
- MVC文件上传 - 使用jquery异步上传并客户端验证类型和大小
本篇体验MVC上传文件,从表单上传过渡到jquery异步上传. MVC最基本的上传文件是通过form表单提交方式 □ 前台视图部分 <% using(Html.BeginForm("F ...
- rpm方式安装gcc缺少依赖项的解决方法
使用rpm方式安装gcc时,有时会报缺少依赖项: libmpfr.so.1 is needed by cpp-4.4.4-13.el6.i686 libppl.so.7 is needed by cl ...
- jquery点击其他地方隐藏div层的实现程序
js代码 $(document).ready(function() { //语言头部的点击事件,显示语言列表 $(".language_selected").click(funct ...
- ubuntu系统软件
1.办公软件:wps 2.浏览器:firefox,opera 3.思维导图:xmind 如果您有好的软件,请推荐给我,谢谢!
- merge into 和 update 的效率对比
以前只考虑 merge into 只是在特定场合下方便才使用的,今天才发现,merge into 竟然会比 update 在更新数据时有这么大的改进.其实呢,merge into部分的update和u ...