大二了,先写下吧,就是感觉这个东西很是神奇,直接存就可以把整个图形存下来了,每次都new node,还有就是那个结构体内部的结构体指针,神奇神奇。
题目链接:点击打开链接
代码:
#include<stdio.h>
#include<algorithm>
using namespace std;
#include<bits/stdc++.h>
typedef struct node
{
int v;
struct node *l,*r;
} node1,*tree;
void build (tree &p,int v1)
{
if(p==NULL)
{
p=new node();
p->v=v1;
p->l=p->r=NULL;
return ;
}
if(v1<p->v)
build(p->l,v1);
else if(v1>p->v)
{
build(p->r,v1);
}
}
tree tree1[55];
bool jud;
bool judge (tree a,tree b)
{
if(a==NULL&&b==NULL)
return true;
else if(a&&b)
{
judge(a->l,b->l);
judge(a->r,b->r);
}
else
jud=false;
}
int main()
{
int T,n,k;
scanf("%d",&T);
// string s[55];
while(T--)
{
int v;
scanf("%d%d",&n,&k);
for(int i=0; i<n; i++)
{
tree p=NULL;
for(int j=0; j<k; j++)
{
scanf("%d",&v);
build(p,v);
}
tree1[i]=p;
}
int ans=0;
for(int i=0; i<n; i++)
{
int flot=1;
for(int j=i+1; j<n; j++)
{
jud=true;
judge(tree1[i],tree1[j]);
if(jud)
{
flot=0;
break;
}
}
ans+=flot;
}
printf("%d\n",ans);
}
return 0;
}
手打一遍代码!!!!!!!学到不少东西。