# 【JZOJ 1500】秤（递归）

5
2 3
4 5
-1 -2
-3 -4
-5 -6
5
2 5
-1 -2
-3 -4
-5 -6
3 4

Fred and Mary might have the same mobile.

#include <cstdio>
using namespace std;
#define maxn 100006
int a1[maxn],b1[maxn],a2[maxn],b2[maxn];
int n1,n2;

int init()
{
scanf("%d",&n1);
for (int i=1;i<=n1;i++)
{
scanf("%d%d",&a1[i],&b1[i]);
if (a1[i]>b1[i])
{
int t=a1[i];
a1[i]=b1[i];
b1[i]=t;
}
}
scanf("%d",&n2);
for (int i=1;i<=n2;i++)
{
scanf("%d%d",&a2[i],&b2[i]);
if (a2[i]>b2[i])
{
int t=a2[i];
a2[i]=b2[i];
b2[i]=t;
}
}
}

bool find(int x,int y)
{
if (a1[x]<=0 && a2[y]<=0 && b1[x]<=0 && b2[y]<=0)
if (a1[x]==a2[y] && b1[x]==b2[y] || a1[x]==b2[y] && a2[y]==b1[x])
return 1;
if (a1[x]<=0 && b1[x]>0 && a2[y]<=0 && b2[y]>0)
if (a1[x]==a2[y] && find(b1[x],b2[y]))
return 1;
if (a1[x]>0 && b1[x]>0 && a2[y]>0 && b2[y]>0)
if (find(a1[x],a2[y]) && find(b1[x],b2[y]) || find(a1[x],b2[y]) && find(b1[x],a2[y]))
return 1;
return 0;
}

int main()
{
init();
if (find(1,1))
printf("Fred and Mary might have the same mobile.");
else
printf("Fred and Mary have different mobiles.");
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120