ZOJ--3710--Friends--二维数组模拟建立关系
来源:互联网 发布:安卓版电子狗软件 编辑:程序博客网 时间:2024/06/04 23:22
题目链接https://vjudge.net/problem/ZOJ-3710
题目大意是输入朋友关系对,双方拥有共同朋友达到数量k之后可以变成朋友。求一段时间后有多少对新的朋友对关系建立起来。
要点:
1、建立friends[from][to]二维数组存储关系对。
2、注意新建立的朋友关系可能会连锁反应建立更多的好友关系。
代码如下:
#include<iostream>#include<cstring>using namespace std;const int maxn=110;int friends[maxn][maxn];int ans;int make_friends(int n,int k){ ans=0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(i==j) continue; if(friends[i][j]==0){ int cnt=0; for(int t=0;t<n;t++){ if(friends[i][t]==1&&friends[j][t]==1) cnt++; } if(cnt>=k){ friends[i][j]=1; friends[j][i]=1; ans++; i=-1; break; //此两行的作用就是让i重新循环,计算要点2中的连锁朋友关系 } } } } return ans;}int main(){ int T,n,m,k,from,to; cin>>T; while(T--){ memset(friends,0,sizeof(friends)); cin>>n>>m>>k; while(m--){ cin>>from>>to; friends[from][to]=1; friends[to][from]=1; } ans=make_friends(n,k); cout<<ans<<endl; } return 0;}
阅读全文
0 0
- ZOJ--3710--Friends--二维数组模拟建立关系
- ZOJ-3710(Friends)
- zoj 3710 Friends
- zoj 3710 Friends
- ZOJ 3710 Friends 暴力
- zoj 3710 Friends
- Friends zoj 3710
- ZOJ 3710 Friends
- zoj 3710 Friends
- ZOJ 3710 Friends
- ZOJ 3710 Friends
- ZOJ 3710Friends(暴力)
- ZOJ 3710 Friends
- ZOJ 3710 Friends
- ZOJ-3710-Friends
- ZOJ 3710 Friends
- Friends ZOJ 3710
- ZOJ 3710Friends
- 数组的处理
- git--Bug分支
- 由前序遍历和中序遍历,求后序遍历
- 重温算法入门经典,PYTHON冒泡排序
- Java递归求某个集合的所有子集组成的集合,即幂集
- ZOJ--3710--Friends--二维数组模拟建立关系
- java中类加载机制、类加载过程和类加载器层次
- Unity3D学习笔记1——Unity大法好呀
- java面向对象
- Android MediaPlayer 多媒体(视频播放器)
- 导致页面顶部空白一行解决方法
- BZOJ 2049 洞穴勘测 (LCT 模板)
- leetcode -- 125. Valid Palindrome 【有效的回文 + 带条件的双指针】
- linux实时系统阵营