打架

版权声明:未经过同意不得转载 https://blog.csdn.net/qq_42500298/article/details/83003879

在这里插入图片描述
在这里插入图片描述
写个类似于并查集的东东就行了

#include<bits/stdc++.h>
#define mn 1111111
#define gc getchar
#define id isdigit
using namespace std;
int n,m,i,x,y,s,t,z,p,q,xudyh,WJMZBMR,jcsb,jiry_2,f[mn];
inline int calc(int x,int y) 
{
 if(!x||!y||x==n||y==n) 
  return 0; 
 return (x-1)*n+y;
}
inline int get(int x) 
{
 if(f[x]==x) 
  return x; 
 return f[x]=get(f[x]);
}
inline void doit(int x,int y)
{
    int fx=get(x),fy=get(y);
    if(fx==fy) 
  puts("DAJIA"),z=1; 
 else 
 {
  f[fy]=fx; 
  puts("HAHA"),z=0;
 }
}
inline int read()
{
 int s=0,w=1; 
 char c=gc();
 while(!id(c)) 
 {
  if(c=='-') 
   w=-1; 
  c=gc();
 }
 while(id(c))
  (s*=10)+=c-48,c=gc();
 return s*w;
}
int main()
{
    n=read(); 
 m=read();
    for(;i<=n*n;i++) 
 f[i]=i;
    for(i=1;i<=m;i++)
    {
        x=read(); 
  y=read(); 
  s=read(); 
  t=read(); 
        if(i>1) 
        {
   if(z) 
    x=read(),y=read(),s=read(),t=read(); 
   else 
    xudyh=read(),WJMZBMR=read(),jcsb=read(),jiry_2=read();
  }
        if(x>s) 
   swap(x,s); 
  if(y>t) 
   swap(y,t);
        if(x<s) 
   p=calc(x,y-1); 
  else 
   p=calc(x-1,y);
  q=calc(x,y); 
  doit(p,q);
    }
    return 0;
} 

来源:zr

猜你喜欢

转载自blog.csdn.net/qq_42500298/article/details/83003879