CSU1840-Lawn mower-简单模拟

本文介绍了一种确保足球场草坪被均匀修剪的算法。该算法通过记录割草机沿长度和宽度方向移动的位置,确保每个区域至少被覆盖一次。通过输入割草路径数据,可以判断草坪是否得到完全修剪。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Y: Lawn mower

Description

​ The International Collegiate Soccer1 Competition (ICSC) is famous for its well-kept rectangular stadiums. The grass playing fields in ICSC stadiums are always 100 meters long, and 75 meters wide. The grass is mowed every week with special lawn mowers, always using the same strategy: first, they make a series of passes along the length of the field, and then they do the same along the width of the field. All passes are straight lines, parallel to the sides of the field.

img The ICSC has hired a new lawn-mower, Guido. Guido is very chaotic, and instead of covering the field incrementally, he likes to choose random starting positions for each of his passes. But he is afraid of not doing a good job and being red by the ICSC, so he has asked you to help him. Write a program to make sure that the grass in the field is perfectly cut: all parts of the field have to be mowed at least once when the mower goes from end to end, and again when the mower goes from side to side.

Input

  Each test case contains 3 lines. The first line contains two integers, nx (0 < nx < 1 000) and ny (0 < nx < 1 000), and a real number w (0

Output

  Print YES if Guido has done a good job, or NO if some part of the field has not been mowed at least once when the mower was travelling along the length of the field, and again when it was travelling along the width.

Sample Input

8 11 10.0
0.0 10.0 20.0 30.0 40.0 50.0 60.0 70.0
0.0 10.0 20.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0
8 10 10.0
0.0 10.0 20.0 30.0 40.0 50.0 60.0 70.0
0.0 10.0 30.0 40.0 50.0 60.0 70.0 80.0 90.0 100.0
4 5 20.0
70.0 10.0 30.0 50.0
30.0 10.0 90.0 50.0 70.0
4 5 20.0
60.0 10.0 30.0 50.0
30.0 10.0 90.0 50.0 70.0
0 0 0.0

Sample Output

YES
NO
YES
NO

其实仔细一想,就是指垂直和水平割草的时候都要全部覆盖一遍
一开始把eps写成1e2我是真的智障……

#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
double hor[1010],ver[1010];
using namespace std;
int main()
{
//  ios::sync_with_stdio(false);
    bool ok;
    int n,m,i;
    double wid;
    while(cin>>n>>m>>wid&&(n||m)){
        for(i=0;i<n;++i){
            cin>>hor[i];
        }
        sort(hor,hor+n);
        for(i=0;i<m;++i){
            cin>>ver[i];
        }
        sort(ver,ver+m);
        ok=hor[0]-wid/2<1e-4&&(hor[n-1]-(75-wid/2)>-1e-7);
//      printf("%7f %7f\n",hor[0]-wid/2,hor[n-1]-(75-wid/2));
        for(i=1;i<n-1&&ok;++i){
//          cout<<hor[i]-hor[i-1]-wid<<endl;
            if(hor[i]-hor[i-1]-1e4>wid){
                ok=false;
//              cout<<1;
            }
        } 
        if(ok){
            ok=(ver[0]-wid/2<1e-4)&&(ver[m-1]-(100-wid/2)>-1e-4);
//          printf("%7f %7f",ver[0],ver[m-1]);
            for(i=1;i<m-1&&ok;++i){
//              cout<<ver[i]-ver[i-1]-wid<<endl;
                if(ver[i]-ver[i-1]-wid>1e-4){
                    ok=false;
//                  cout<<2;
                }
            }
        }
        if(ok){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}


/**********************************************************************
    Problem: 1840
    User: CSUzick
    Language: C++
    Result: AC
    Time:16 ms
    Memory:1716 kb
**********************************************************************/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值