poj2766

来源:互联网 发布:win10网络重置命令 编辑:程序博客网 时间:2024/06/14 04:52
#include <iostream>#include <string.h>#include <stdio.h>using namespace std;int cases;int n,r;int x,y;int mapn[55][55];bool solve(){    int tmp;    if(y==0)tmp=0;    else if(y==n+1) tmp=2;    else if(x==0) tmp=1;    else if(x==n+1) tmp=3;    while(1)    {        if(tmp%4==0)        {            for(y++;mapn[x][y]!=1;y++)                if(y==n+1) return true;        }        else if(tmp%4==1)        {            for(x++;mapn[x][y]!=1;x++)                if(x==n+1) return true;        }        else if(tmp%4==2)        {            for(y--;mapn[x][y]!=1;y--)                if(y==0) return true;        }        else if(tmp%4==3)        {            for(x--;mapn[x][y]!=1;x--)                if(x==0) return true;        }        tmp++;        if(tmp>1000) return false;    }}int main(){    cin>>cases;    while(cases--)    {        memset(mapn,0,sizeof(mapn));        scanf("%d%d",&n,&r);        for(int i=0;i<r;i++)            {                scanf("%d%d",&x,&y);                mapn[x][y]=1;            }        scanf("%d%d",&x,&y);        if(solve())        cout<<x<<" "<<y<<endl;        else            cout<<"0 0"<<endl;    }    return 0;}