• poj 1584


    比较水的题,但是要细心,把情况考虑清楚

    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    using namespace std;
    const int maxn=10000;
    const double eps=1e-8;
    int n,f[maxn];
    double rad;
    struct Point
    {
    	double x,y;
    };
    Point ver[maxn],pel;
    double cross(Point a,Point b,Point c,Point d)
    {
    	return (b.x-a.x)*(d.y-c.y)-(b.y-a.y)*(d.x-c.x);
    }
    double dis(Point a,Point b)
    {
    	return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
    }
    double getD(Point a,Point b,Point c)
    {
    	return fabs(cross(a,b,a,c))/dis(a,b);
    }
    int main()
    {
    	while(scanf("%d",&n)&&n>=3)
    	{
    		scanf("%lf%lf%lf",&rad,&pel.x,&pel.y);
    		int i;
    		for(i=0;i<n;i++)
    			scanf("%lf%lf",&ver[i].x,&ver[i].y);
    		ver[n].x=ver[0].x;ver[n].y=ver[0].y;
    		int flag=1;
    		for(i=2;i<=n;i++)
    		{
    			double tem=cross(ver[i-2],ver[i-1],ver[i-1],ver[i]);
    			if(fabs(tem)<eps) f[i]=0;
    			else if(tem<0) f[i]=-1;
    			else f[i]=1;
    		}
    		int ju=0;
    		for(i=3;i<=n;i++)
    		{
    			if(f[i]*f[i-1]<0)
    			{
    				flag=0;
    				break;
    			}
    			else 
    			{
    				if(f[i]!=0) ju=f[i];
    			}
    		}
    		if(!flag) printf("HOLE IS ILL-FORMED\n");
    		else
    		{
    			flag=1;
    			int flag2=1;
    			if(ju==1)
    			{
    			for(i=0;i<n;i++)
    			{
    				if(cross(ver[i],ver[i+1],ver[i],pel)<eps)
    				{
    					flag=0;
    					break;
    				}
    			}
    			}
    			else if(ju==-1)
    			{
    				for(i=0;i<n;i++)
    				{
    				if(cross(ver[i],ver[i+1],ver[i],pel)>-eps)
    				{
    					flag=0;
    					break;
    				}
    			}
    			}
    			else flag=0;
    			if(flag)
    			{
    				for(i=0;i<n;i++)
    				{
    					if(getD(ver[i],ver[i+1],pel)-rad<=-eps)
    					{
    						flag2=0;
    						break;
    					}
    				}
    			}
    			if(flag&&flag2) printf("PEG WILL FIT\n");
    			else printf("PEG WILL NOT FIT\n");
    		}
    	}
    	return 0;
    }


  • 相关阅读:
    ELK初学搭建(logstash)
    认识基本的UI资源
    C# 枚举器
    NGUI---使用脚本控制聊天系统的内容显示,输入事件交互
    NGUI----简单聊天系统一
    C# 类型、存储和变量
    C# Execl表格文件转xml文件
    网易云音乐如何从0到亿级用户整理笔记
    如何成为一名完美的传道授业解惑者
    grouping sets,cube,rollup,grouping__id,group by
  • 原文地址:https://www.cnblogs.com/lj030/p/3002229.html
Copyright © 2020-2023  润新知