markdown 在线制作ppt json校验和格式化工具

POJ 1611

#include <stdio.h>
#include <iostream>
#define M_500 505
#define M_30000 30005
using namespace std;

int pre[M_30000];
int ans[M_30000];
int m_1[M_500];

int n;
int m;

void init();
int find_pre(int s);

int main()
{
    //freopen("acm.acm","r",stdin);
    //freopen("out.acm","w",stdout);
    int num_m;
    int i;
    int k;
    int j;
    int code;
    int tem;
    while(cin>>n>>m)
    {
        if(n == 0 && m == 0)
        {
             break;
        } 
        init();
    //    cout<<"ans[0]"<<ans[0]<<endl;
        for(i = 0; i < m; ++ i)
        {
        //    cout<<"------------"<<i<<endl;
            cin>>k;
            cin>>m_1[i];
    //        cout<<" k "<<k<<endl;
            
            for(j = 1; j < k; ++ j)
            {
                  cin>>code;
                  find_pre(code);
                  find_pre(m_1[i]);
                  if(pre[code] != pre[m_1[i]])
                {
                       //      if(i == 2)
                      //       {
                      //            cout<<"*************** "<<ans[pre[m_1[i]]]<<endl;
                       //           cout<<ans[pre[code]]<<endl;
                      //            }
                        
                      ans[pre[m_1[i]]] += ans[pre[code]];
                  //    if(i == 2)
                 //     {
                 //           cout<<ans[pre[code]]<<endl;
                  //     cout<<ans[pre[m_1[i]]]<<" @@@@@@@@@@@@@@ "<<pre[m_1[i]]<<endl;
                  //    }
                      pre[pre[code]] = pre[m_1[i]];
                  }
            }
        //    cout<<ans[find_pre(1)]<<endl;
        //    cout<<find_pre(1)<<" ((((((((((((((( "<<endl;
        }
    //    for(i = 0; i < n; ++ i)
    //    {
    //        cout<<ans[i]<<" ";
    //    }
    //    cout<<"///////////////////////////////////////////"<<endl;
    //    cout<<find_pre(0)<<" ((((((((((((((( "<<endl;
        cout<<ans[find_pre(0)] <<endl; 
        
    }
    return 0;
}

void init()
{
    int i;
    int j;
    for(i = 0; i < n; ++ i)
    {
        pre[i] = i;
        ans[i] = 1;
    }
}

int find_pre(int s)
{
    if(pre[s] == s)
    {
        return pre[s];
    }
    else 
    {
        pre[s] = find_pre(pre[s]);
    }
    return pre[s];
}

 

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。 

技术网站地址: vmfor.com

posted @ 2015-06-10 16:35  GavinHacker  阅读(122)  评论(0编辑  收藏  举报
markdown 在线制作ppt json校验和格式化工具