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

  • 相关阅读:
    canvas直线学习
    移动端页面练习
    IOS 本地推送(UILocalNotification)
    IOS 社交分享
    IOS 通讯录 (访问,添加,修改)
    IOS 蓝牙(GameKit、Core Bluetooth)
    IOS 获取更多的设备信息
    IOS 摇一摇的方法
    IOS Core Motion、UIAccelerometer(加速计使用)
    IOS UIDevice距离传感器(打开 关闭)
  • 原文地址:https://www.cnblogs.com/smuzoey/p/11787448.html
Copyright © 2011-2022 走看看