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;
    	}
    }

  • 相关阅读:
    QtCreator无法编辑源文件
    【Newtonsoft.Json】自己实现JsonConverter ,精简返回的数据结果
    Ghostscript 将PDF文件转换成PNG图片 问题一二
    Nginx--面试基础必会
    Nginx日志配置
    Nginx缓存原理及机制
    Nginx限流
    Nginx 实现 Rewrite 跳转
    Nginx正确配置Location
    渐进深入理解Nginx
  • 原文地址:https://www.cnblogs.com/smuzoey/p/11787448.html
Copyright © 2011-2022 走看看