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

  • 相关阅读:
    函数表达式
    BOM
    让超出容器高度的内容滚动显示但不出现滚动条
    插件书写示例
    php中redis的安装
    日常工作bug总结
    pip freeze requirements.txt命令迁移模块
    Django18-中间件和cache实现限制用户访问频率
    Django17-文件上传下载
    Django16-cache缓存
  • 原文地址:https://www.cnblogs.com/smuzoey/p/11787448.html
Copyright © 2011-2022 走看看