POJ 1694 C++ (排序)

//不会敲,是偶看过别人的结题报告后敲的,学习下
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct Node
{ int label;
   int cnt;
   int leaf[200];
};
Node tree[200];
int solve(int i)
{   int  stone[200],result,temp;
    if(tree[i].cnt==0)
       return 1;
     for(int j=0;j<tree[i].cnt;j++)
         stone[j]=solve(tree[i].leaf[j]);

     sort(stone,stone+tree[i].cnt);
     result=stone[tree[i].cnt-1];
     temp=result-1;
     for(int k=tree[i].cnt-2;k>=0;k--)
        { if(temp-stone[k]>=0)
             temp--;
           else
             {result=result+stone[k]-temp;
              temp=stone[k]-1;
              }
         }

       return result;
}
int main()
{ int n,m;
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
  scanf("%d",&n);
  while(n--)
       { scanf("%d",&m);
         for(int i=1;i<=m;i++)
             {  scanf("%d%d",&tree[i].label,&tree[i].cnt);
                for(int j=0;j<tree[i].cnt;j++)
                   scanf("%d",&tree[i].leaf[j]);
              }
         printf("%d\n",solve(1));
       }      

   return 0;
}
                

posted on 2008-11-26 01:01 蜗牛 阅读(1154) 评论(1)  编辑 收藏 引用 所属分类: ACM ICPC

评论

# re: POJ 1694 C++ (排序) 2009-06-19 20:06 qweq

sdadhouO UourepoUDJZSLM aqi sOUEOPQUeo iwoqye-  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2008年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

导航

统计

常用链接

留言簿(1)

随笔分类(20)

随笔档案(20)

Favorites

搜索

最新评论

阅读排行榜

评论排行榜