Friends----暴力枚举
来源:互联网 发布:free mobile java在线 编辑:程序博客网 时间:2024/06/06 01:38
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.
Input
There are multiple test cases.
The first lien of the input contains an integer T (about 100) indicating the number of test cases. Then T cases follow. For each case, the first line contains three integers n, m, k (1 ≤ n ≤ 100, 0 ≤ m ≤n×(n-1)/2, 0 ≤ k ≤ n, there will be no duplicated friendship) followed by m lines showing the current friendship. The ith friendship contains two integers ui, vi (0 ≤ ui, vi < n, ui ≠ vi) indicating there is friendship between person ui and vi.
Note: The edges in test data are generated randomly.
Output
For each case, print one line containing the answer.
Sample Input
34 4 20 10 21 32 35 5 20 11 22 33 44 05 6 20 11 22 33 44 02 0
Sample Output
204
Author: ZHUANG, Junyuan
Contest: The 10th Zhejiang Provincial Collegiate Programming Contest
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3710
这个题是我傻了,我把它想难了,题目的意思是说告诉你几个确定的关系,问你能再推出来几个确定的关系。
暴力枚举就好。。
代码:
#include <cstdio>#include <cstring>#include <iostream>using namespace std;bool map1[101][101];int g[101][101];int main(){ int t; scanf("%d",&t); while(t--){ memset(map1,false,sizeof(map1)); int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=0;i<m;i++){ int x,y; scanf("%d%d",&x,&y); map1[x][y]=true; map1[y][x]=true; } int sum=0; while(1){ int ans=0; memset(g,0,sizeof(g)); for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(map1[i][j]&&map1[j][i]) continue; for(int z=0;z<n;z++){ if(map1[i][z]&&map1[j][z]){ g[i][j]++; } } if(g[i][j]>=k){ ans++; map1[i][j]=true; map1[j][i]=true; } } } if(ans==0){ break; } sum+=ans; } cout<<sum<<endl; } return 0;}
- Friends----暴力枚举
- Friends (暴力枚举)
- HDOJ 5305 Friends 暴力枚举
- ZOJ3710 Friends(暴力枚举,模拟)
- ZOJ 3710 Friends 暴力
- ZOJ Friends(暴力)
- 【BZOJ3916】【Baltic2014】friends 暴力
- ZOJ 3710Friends(暴力)
- bzoj3916 [Baltic2014]friends 暴力
- 暴力枚举
- 暴力枚举?
- 暴力枚举
- 暴力枚举
- 暴力枚举
- ZOJ 3710 Friends(暴力)
- hdu 5305 Friends(暴力)
- ZOJ 3710 Friends(枚举)
- ZOJ 3710 Friends(暴力或map)
- java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents witho
- Android主流网络请求开源库的对比(Android-Async-Http、Volley、OkHttp、Retrofit)
- ELKStack日志分析系统单机安装
- CentOS 7 目录结构
- salesforce 零基础学习(六十四)页面初始化时实现DML操作
- Friends----暴力枚举
- 关于C#中导出数据几种换行符
- 认识View-01
- 424. Longest Repeating Character Replacement
- 医疗行业应用交付解决方案【ANS SOLUTIONS】
- 在linux上搭建git服务器
- iOS-文件路径 temp document library 等
- jvm调试笔录
- 设计模式之观察者模式