UVALive 4954 Lawn mower (简单模拟题)

题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=16406


题目大意:

    给定一块75*100的区域,用一个宽度为w的割草机去割。给定一些横着的中间位置,竖着的中间位置。问这些操作是否能够横着覆盖整块区域,并且竖着覆盖整个区域。可以的话,输出"YES",不能的话输出“NO”。


解题:

    先将这些中间位置排序,看能否连上,不能连上直接break。同时最后看起始位置是否小于等于0,最后的位置是否大于等于75/100。


代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <set>
#define eps 1e-9
using namespace std;
int main()
{
	int x,y;
	double w,hen[1010],shu[1010],maxh,maxs,tmp;
	bool flag;
	while(scanf("%d%d%lf",&x,&y,&w))
	{
		if(x==0&&y==0)break;
        for(int i=0;i<x;i++)
			scanf("%lf",&shu[i]);
		for(int i=0;i<y;i++)
			scanf("%lf",&hen[i]);
		sort(hen,hen+y);
		sort(shu,shu+x);
		maxs=shu[0]+w/2;
		maxh=hen[0]+w/2;
        if(hen[0]-w/2<=0.0)flag=true;
		else flag=false;
		if(flag&&(shu[0]-w/2)<=0.0)flag=true;
		else flag=false;
		if(flag)
		{
           if(x>1)
		   {
			   for(int i=1;i<x;i++)
			   {
                   tmp=shu[i]-w/2;
				   if(tmp-maxs<=0.0)
					   maxs=shu[i]+w/2;
				   else 
				   {
					   flag=false;
					   break;
				   }
			   }
		   }
		   if(flag&&y>1)
		   {
			   for(int i=1;i<y;i++)
			   {
				   tmp=hen[i]-w/2;
				   if(tmp-maxh<=0.0)
					   maxh=hen[i]+w/2;
				   else
				   {
					   flag=false;
					   break;
				   }
			   }
		   }
		   if(flag)
		   {
			   if((maxs-75.0>=0.0)&&(maxh-100.0>=0.0))
				   flag=true;
			   else flag=false;
		   }
		}
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}









你可能感兴趣的:(模拟,水题,区域赛)