• Codeforces 115A Party (并查集思维)


    题意:

    给你每个人的上级,并且一个人和他的所有上级都不能在一个party(小组)中(这点是根据题目给出的两点推导出来的),问最少需要几个party。

    思路:

    并查集,找一个集合中层级数最多的就是最少需要的party数量。

    #include<bits/stdc++.h>
    using namespace std;
    int in[2010], a[2010];
    int main() {
    	//freopen("in.txt", "r", stdin);
    	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    	int n, maxx = 0; cin >> n;
    	for (int i = 1; i <= n; ++i)cin >> a[i];
    	for (int i = 1; i <= n; ++i)//利用并查集思想
    		for (int j = i, k = 1; j != -1;j = a[j],k++)
    			maxx = maxx > k ? maxx : k;
    	cout << maxx << endl;
    }
    

    The desire of his soul is the prophecy of his fate
    你灵魂的欲望,是你命运的先知。

  • 相关阅读:
    solr 的全量更新与增量更新
    solr 服务器的搭建
    Mysql 问题
    App 微信支付
    App 支付宝支付
    Linux 常见命令
    [备注] 钉钉使用教程
    PARAMETER和ARGUMENT的区别
    无界面浏览器
    URLs ...
  • 原文地址:https://www.cnblogs.com/RioTian/p/13548583.html
Copyright © 2020-2023  润新知