标签:style color os io for ar amp line
这道题的思路,就是每次记下该点到父结点的个数,并记录下其下的结点个数。之后,每次"C"时,将总的减去它所压的方块,即答案!!!(也是参考别人的~-?)
<pre name="code" class="cpp">#include<stdio.h>
#include<iostream>
using namespace std;
#define max 30010
struct node
{
int parent;//最上面的元素
int up;// 上面的个数
int down;// 下面的个数
};
struct node st[max];
int find(int x)
{
int p;
if(st[x].parent !=x)
{
p=st[x].parent ;
st[x].parent =find(st[x].parent);
st[x].up+=st[p].up;
}
return st[x].parent ;
}
void uion(int x,int y)
{
x=find(x);
y=find(y);
st[y].parent=x;
st[y].up=st[x].down ;
st[x].down+=st[y].down ;
}
int main()
{
char s[3];
int i,x,y;
int parent;
int n;
scanf("%d",&n);
for(i=0;i<max;i++)
{
st[i].parent=i;
st[i].down=1;
st[i].up=0;
}
while(n--)
{
scanf("%s",s);
if(s[0]==‘M‘)
{
scanf("%d%d",&x,&y);
uion(x,y);
}
else if(s[0]==‘C‘)
{
scanf("%d",&x);
parent=find(x);
printf("%d\n",st[parent].down -st[x].up -1);
}
}
return 0;
}
POJ 1988 Cube Stacking(转),布布扣,bubuko.com
标签:style color os io for ar amp line
原文地址:http://www.cnblogs.com/bofengyu/p/3909734.html