zoukankan      html  css  js  c++  java
  • Codeforces Round #630 (Div. 2) A. Exercising Walk(水题)

    Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat!

    Initially, Alice's cat is located in a cell (x,y)(x,y) of an infinite grid. According to Alice's theory, cat needs to move:

    • exactly aa steps left: from (u,v)(u,v) to (u1,v)(u−1,v) ;
    • exactly bb steps right: from (u,v)(u,v) to (u+1,v)(u+1,v) ;
    • exactly cc steps down: from (u,v)(u,v) to (u,v1)(u,v−1) ;
    • exactly dd steps up: from (u,v)(u,v) to (u,v+1)(u,v+1) .

    Note that the moves can be performed in an arbitrary order. For example, if the cat has to move 11 step left, 33 steps right and 22 steps down, then the walk right, down, left, right, right, down is valid.

    Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area [x1,x2]×[y1,y2][x1,x2]×[y1,y2] , i.e. for every cat's position (u,v)(u,v) of a walk x1ux2x1≤u≤x2 and y1vy2y1≤v≤y2 holds.

    Also, note that the cat can visit the same cell multiple times.

    Can you help Alice find out if there exists a walk satisfying her wishes?

    Formally, the walk should contain exactly a+b+c+da+b+c+d unit moves (aa to the left, bb to the right, cc to the down, dd to the up). Alice can do the moves in any order. Her current position (u,v)(u,v) should always satisfy the constraints: x1ux2x1≤u≤x2 , y1vy2y1≤v≤y2 . The staring point is (x,y)(x,y) .

    You are required to answer tt test cases independently.

    Input

    The first line contains a single integer tt (1t1031≤t≤103 ) — the number of testcases.

    The first line of each test case contains four integers aa , bb , cc , dd (0a,b,c,d1080≤a,b,c,d≤108 , a+b+c+d1a+b+c+d≥1 ).

    The second line of the test case contains six integers xx , yy , x1x1 , y1y1 , x2x2 , y2y2 (108x1xx2108−108≤x1≤x≤x2≤108 , 108y1yy2108−108≤y1≤y≤y2≤108 ).

    Output

    For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.

    You can print each letter in any case (upper or lower).

    Example
    Input
    Copy
    6
    3 2 2 2
    0 0 -2 -2 2 2
    3 1 4 1
    0 0 -1 -1 1 1
    1 1 1 1
    1 1 1 1 1 1
    0 0 0 1
    0 0 0 0 0 1
    5 1 1 1
    0 0 -100 -100 0 100
    1 1 5 1
    0 0 -100 -100 100 0
    
    Output
    Copy
    Yes
    No
    No
    Yes
    Yes
    Yes
    考虑到向右走三步再向左走两步等于向右走一步,可以得到水平方向和垂直方向的位移 如果越界了肯定不行;其次位移为0但有可能是左右/上下移动距离相等,这时特判一下x2-x1或y2-y1是否大于等于1(只要有一格就能满足)。
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            long long int a,b,c,d,x1,y1,x2,y2,x,y;
            cin>>a>>b>>c>>d;
            cin>>x>>y>>x1>>y1>>x2>>y2;
            long long sp,cz;
            sp=b-a,cz=d-c;
            if(sp>=0)
            {
                if(x2-x<sp)
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            else
            {
                if(x-x1<(-sp))
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            if(cz>=0)
            {
                if(y2-y<cz)
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            else
            {
                if(y-y1<(-cz))
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            if(((a||b)&&x2-x1==0)||((c||d)&&y2-y1==0))
            {
                cout<<"NO"<<endl;
                continue;
            }
            cout<<"YES"<<endl;
        }
        
    }


    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            long long int a,b,c,d,x1,y1,x2,y2,x,y;
            cin>>a>>b>>c>>d;
            cin>>x>>y>>x1>>y1>>x2>>y2;
            long long sp,cz;
            sp=b-a,cz=d-c;
            if(sp>=0)
            {
                if(x2-x<sp)
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            else
            {
                if(x-x1<(-sp))
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            if(cz>=0)
            {
                if(y2-y<cz)
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            else
            {
                if(y-y1<(-cz))
                {
                    cout<<"NO"<<endl;
                    continue;
                }
            }
            if(((a||b)&&x2-x1==0)||((c||d)&&y2-y1==0))
            {
                cout<<"NO"<<endl;
                continue;
            }
            cout<<"YES"<<endl;
        }
        
    }
  • 相关阅读:
    Opencv 图片边缘检测和最小外接矩形
    python matplotlib包图像配色方案
    python matplotlib 绘图 和 dpi对应关系
    python 工具 二进制文件处理之——去掉指定长度数据包头
    python 工具 二进制文件处理之——大小端变换
    Prime Path(POJ 3126 BFS)
    Travel(HDU 5441 2015长春区域赛 带权并查集)
    树上战争(HDU 2545 并查集求解点到根节点长度)
    More is better(hdu 1856 计算并查集集合中元素个数最多的集合)
    How Many Tables(POJ 1213 求连通分量)
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12615071.html
Copyright © 2011-2022 走看看