POJ 1584.A Round Peg in a Ground Hole
来源:互联网 发布:ps类书籍知乎 编辑:程序博客网 时间:2024/05/17 04:53
题目:http://poj.org/problem?id=1584
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0x7fffffff#define LFINF 1e10#define eps 1e-7#define MAXN 100105#define PI 3.14159265358979323846using namespace std;struct Point { double x,y; Point(double x=0,double y=0):x(x),y(y) {} };typedef Point Vector;Vector operator + (Vector A,Vector B) { return Vector(A.x+B.x,A.y+B.y); } Vector operator - (Vector A,Vector B) { return Vector(A.x-B.x,A.y-B.y); } Vector operator * (Vector A,double p) { return Vector(A.x*p,A.y*p); } Vector operator / (Vector A,double p) { return Vector(A.x/p,A.y/p); } int dcmp(double x){ if(fabs(x)<eps) return 0; else return x<0?-1:1; }int n;double r;Point c;Point node[1010];double Dot(Vector A,Vector B) { return A.x*B.x+A.y*B.y; }double Length(Vector A) { return sqrt(Dot(A,A)); }double Angle(Vector A,Vector B) { return acos(Dot(A,B)/Length(A)/Length(B)); }double Cross(Vector A,Vector B) { return (A.x*B.y-A.y*B.x); }bool isConvexBag(){int dir = 0;for(int i = 0; i < n; i++){int tmp = dcmp(Cross(node[i+1]-node[i],node[i+2]-node[i+1]));if(dir==0)dir = tmp;if(dir*tmp<0)return false;}return true;}bool isInside(){double angle = 0.0;for(int i = 0; i < n; i++)angle += Angle(node[i]-c,node[i+1]-c);if(dcmp(angle)==0)return false;if(dcmp(angle+PI*2)==0||dcmp(angle-PI*2)==0)return true;if(dcmp(r)==0)return true;return false;}double Distance(Point A, Point B, Point C){//A - BCreturn fabs(Cross(B-A,C-A)/Length(C-B));} bool isCircleInside(){for(int i = 0; i < n; i++){if(dcmp(Distance(c,node[i],node[i+1])-r)!=-1)continue;return false;}return true;}int main(){while(cin>>n){if(n<3)break;cin>>r>>c.x>>c.y;for(int i = 0; i < n; i++)cin>>node[i].x>>node[i].y;node[n] = node[0];node[n+1] = node[1];if(!isConvexBag()){cout<<"HOLE IS ILL-FORMED\n";continue;}if(isInside()&&isCircleInside())cout<<"PEG WILL FIT\n";else cout<<"PEG WILL NOT FIT\n";}}总结: 几何题. 首先判断给定的多边形是否是凸包, 然后判断圆心是否在多边形内, 最后求每条边到圆心的距离来判断圆是否能放进多边形内, 都是模板.
阅读全文
0 0
- POJ 1584.A Round Peg in a Ground Hole
- POJ 1584 A Round Peg in a Ground Hole
- poj 1584 A Round Peg in a Ground Hole
- POJ 1584 A Round Peg in a Ground Hole
- POJ 1584 A Round Peg in a Ground Hole
- poj 1584 A Round Peg in a Ground Hole
- poj 1584 A Round Peg in a Ground Hole
- POJ 1584--A Round Peg in a Ground Hole
- POJ 1584 A Round Peg in a Ground Hole
- A Round Peg in a Ground Hole - POJ 1584
- POJ 1584:A Round Peg in a Ground Hole
- poj 1584 A Round Peg in a Ground Hole
- poj 1584 A Round Peg in a Ground Hole
- POJ 1584[A Round Peg in a Ground Hole]题解
- A Round Peg in a Ground Hole
- poj1584A Round Peg in a Ground Hole
- poj1584 A Round Peg in a Ground Hole
- poj1584 A Round Peg in a Ground Hole
- Java如何将字符串转化为JSON(json-lib)
- 德式秘籍:产品总监最该学会的管理方法是什么?(一)
- 网页解析器
- 如何运营垂直类产品
- 获取文件路径----os.listdir()和os.walk()
- POJ 1584.A Round Peg in a Ground Hole
- 如何更好的解决问题 : The puzzle of die
- sql查询优化实用篇
- 【ES6】Proxy
- 第16周—UDP通信(作业1)
- [大并发]自虐Apache,ab压力测试
- 逻辑回归
- mybatis详解-(11)配置多个数据源
- RTC Meetup | 这可能是年底最大、最有料的实时音视频开发者聚会交流