111

#include"stdio.h"
#include"string.h"
#include"iostream"
using namespace std;
const int M=41111;
int f[M];
struct st
{
     int x,y;
}node[M];
int finde(int x,int L,char ch)
{
     if(x!=f[x])
     {
          int t=f[x];
          f[x]=finde(f[x],L,ch);
          //printf("-->%d %d\n",t,x);
          if(ch=='E')
          {
               node[x].x=node[x].x+L;
               node[x].y=node[x].y;
          }
          else if(ch=='W')
          {
               node[x].x=node[x].x-L;
               node[x].y=node[x].y;
          }
          else if(ch=='N')
          {
               node[x].x=node[x].x;
               node[x].y=node[x].y+L;
          }
          else if(ch=='S')
          {
               node[x].x=node[x].x;
               node[x].y=node[x].y-L;
          }


     }
     return f[x];
}
void make(int a,int b,int L,char ch)
{
     int x=finde(a,L,ch);
     int y=finde(b,L,ch);
     if(x!=y)
     {
          f[y]=x;
          if(ch=='E')
          {
               node[y].x=node[x].x+L;
               node[y].y=node[x].y;
          }
          else if(ch=='W')
          {
               node[y].x=node[x].x-L;
               node[y].y=node[x].y;
          }
          else if(ch=='N')
          {
               node[y].x=node[x].x;
               node[y].y=node[x].y+L;
          }
          else if(ch=='S')
          {
               node[y].x=node[x].x;
               node[y].y=node[x].y-L;
          }
     }


}
int main()
{
     int i,m,n,a,b,L;
     char ch[3];
     while(scanf("%d%d",&n,&m)!=-1)
     {
          for(i=1;i<=n;i++)
               f[i]=i;
          while(m--)
          {
               scanf("%d%d%d%s",&a,&b,&L,ch);
               make(a,b,L,ch[0]);
          }
          for(i=1;i<=n;i++)
          printf("%d %d\n",node[i].x,node[i].y);
     }
     return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值