Content

Friday, October 26, 2018

Knight Chess

Problem Link

My Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};
int fy[]={-1,  1, -2,  2, -2,  2, -1,  1};
int dx[]={-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dy[]={1, 1, 1, 0, 0, 0, -1, -1, -1};

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        vector<pair<ll,ll> >pos;
        int n, cnt = 0;
        ll x, y, A, B;
        cin>>n;
        for(int i = 0; i < n; i++)
        {
            cin>>x>>y;
            for(int k = 0; k < 8; k++)
            {
                pos.push_back(make_pair(x+fx[k],y+fy[k]));
            }
        }
        cin>>A>>B;
        for(int i = 0; i < pos.size(); i++)
        {
            for(int k = 0; k < 9; k++)
            {
                if(pos[i].first==(A+dx[k]) && pos[i].second==(B+dy[k]))
                    cnt++;
            }
        }
        //cout<<cnt<<endl;
        if(cnt>=9)
            printf("YES\n");
        else
            printf("NO\n");
    }

    return 0;
}

No comments:

Post a Comment