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;
    }
    
}
复制代码

 

posted @   脂环  阅读(360)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
主题色彩