zoukankan      html  css  js  c++  java
  • ZOJ Problem Set

    题目链接

    Alice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less than k friends in common, they will become friends in several days. Currently, there are totally n people in the country, and m friendship among them. Assume that any new friendship is made only when they have sufficient friends in common mentioned above, you are to tell how many new friendship are made after a sufficiently long time.

    题目大意:共有n个人,某两个人是朋友这样的关系有m个, 如果两个人不是朋友,但是他们的共同好友有k个及以上,则他们为朋友。

    #include<cstdio>
    #include<cmath>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    #include<cstdlib>
    #include<string>
    using namespace std;
    int mp[110][110];
    int num, n, m, k, ans, T;
    int main()
    {
    	cin >> T;
    	while(T--) {
    		memset(mp, 0, sizeof(mp));
    		ans = 0;
    		cin >> n >> m >> k;
    		for(int i = 1; i <= m; i++) {
    			int u, v;
    			cin >> u >> v;
    			mp[u][v] = 1;
    			mp[v][u] = 1;  // 两个人是朋友则为1
    		}
    		bool ok = 1;
    		while(ok) {  // 因为根据共同朋友的数量,朋友关系必须更新
    			ok = 0;
    			for(int i = 0; i < n - 1; i++) {
    				for(int j = i + 1; j < n; j++) {
    					if(!mp[i][j]) {
    						num = 0;
    						for(int q = 0; q < n; q++) {
    							if(mp[i][q] == 1 && mp[q][j] == 1) 
    								num++;
    						}
    						if(num >= k) {
    							mp[i][j] = 1;
    							mp[j][i] = 1;
    							ans++;
    							ok = 1;
    						}
    					}
    				}
    			}
    		}
    		cout << ans << endl;
    	}
    }

  • 相关阅读:
    手写堆排序和归并排序
    海量数据处理
    HDU 1532 --&&-- POJ1273 dinic 算法
    POJ 3159 最短路 SPFA
    POJ 1459 网络流 EK算法
    8.14比赛j题 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87813#overview
    单链表---邻接表
    poj 1273 ---&&--- hdu 1532 最大流模板
    HDU 2603 二分匹配
    UVA 796 连通图求桥
  • 原文地址:https://www.cnblogs.com/smuzoey/p/11787448.html
Copyright © 2011-2022 走看看