栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1767 A Round Peg in a Gro...

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1767 A Round Peg in a Gro...

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <algorithm>using namespace std;#define maxn 2000#define eps 10E-9struct Point{    double x, y;    Point operator-(const Point &a) const    {        Point ret;        ret.x = x - a.x;        ret.y = y - a.y;        return ret;    }} point[maxn], peg;double pegr;int n;int dblcmp(double a){    if (fabs(a) < eps)        return 0;    return a >0?1 : -1;}double xmult(const Point &a, const Point &b){    return a.x * b.y - b.x * a.y;}void input(){    scanf("%lf%lf%lf", &pegr, &peg.x, &peg.y);    for (int i =0; i < n; i++)        scanf("%lf%lf", &point[i].x, &point[i].y);    int t =0;    int i =0;    while (i < n && t ==0)    {        t = dblcmp(xmult(point[(i +1)%n] - point[i], point[(i +2)%n] - point[i]));        i++;    }    if (t <0)        reverse(point, point + n);}bool convex(){    for (int i =0; i < n; i++)        if (dblcmp(xmult(point[(i +1)%n] - point[i], point[(i +2)%n] - point[(i +1)%n]))    <0) return false;    return true;}bool inconvex(){    for (int i =0; i < n; i++)        if (dblcmp(xmult(point[(i +1)%n] - point[i], peg - point[(i +1)%n])) <=0) return false;    return true;}double dist(const Point &a, const Point &b){    Point p;    p = a - b;    return sqrt(p.x * p.x + p.y * p.y);}bool ok(){    for (int i =0; i < n; i++)        if (dblcmp(abs(xmult(peg - point[i], point[(i +1)%n] - point[i]))/dist(point[i], point[(i +1)%n]) - pegr) <0) return false;    return true;}int main(){    while (scanf("%d", &n) != EOF)    {        if (n <3) break;        input();        if (!convex()) printf("HOLE IS ILL-FORMEDn");        else if (!inconvex()||!ok()) printf("PEG WILL NOT FITn");        else printf("PEG WILL FITn");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382217.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号