csu1840Lawn 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.

    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 fi rst line contains two integers, nx (0 < nx < 1 000) and ny (0 < nx < 1 000), and a real number w ( 0<w50 0<w≤50), which represents the width of the cut of that particular lawn mower. The next line describes the end-to-end passes (along the length of the field), and contains nx real numbers xi ( 0xi75 0≤xi≤75) describing the starting positions of the mower's center in Guido's end-to-end passes. The last line describes the side-to-side passes, with ny real numbers yi ( 0yi100 0≤yi≤100).

  The end of the test cases is signalled with a line that contains the numbers 0 0 0.0. You should generate no output for this line, as it is not a test case.

  Real numbers for w, xi and yi can have up to 7 digits after the decimal point, and any cut will also include its boundaries. For example, if a 2.0-meter wide cut is performed along the 10.0-meter mark, then a strip of grass from 9.0 to 11.0 (including both) will be considered "cut".

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

水题呀,赶快切了,排序一下再维护标记
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string.h>
using namespace std;
double xi[1005],yi[1005];
int main()
{
    int nx,ny;
    double w;
    while(cin>>nx>>ny>>w)
    {
        bool suc=true;
        if(nx==0&&ny==0&&abs(w)<1e-5)
            break;
        for(int i=0;i<nx;i++)
            cin>>xi[i];
        for(int i=0;i<ny;i++)
            cin>>yi[i];
        sort(xi,xi+nx);
        sort(yi,yi+ny);
        double endx=xi[0]+w/2.0;
        double endy=yi[0]+w/2.0;
        for(int i=1;i<nx;i++)
            if(endx<xi[i]-w/2.0)
            {
                suc=false;
                break;
            }
            else
                endx=xi[i]+w/2.0;
        if(endx<75&&suc)
            suc=false;
        if(suc)
        {
            for(int i=1;i<ny;i++)
            if(endy<yi[i]-w/2.0)
            {
                suc=false;
                break;
            }
            else
                endy=yi[i]+w/2.0;
            if(endy<100)
                suc=false;
        }
        if(suc)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值