题目链接:https://cn.vjudge.net/contest/280949#problem/F

题目大意:给你n个人,然后给你m个关系,每个关系输入t1, t2 .代表t1和t2是朋友关系(双向关系)。然后输入一个k,代表两个人是亲密的朋友关系的话,就至少有k个共同的朋友,然后问你题目中这样的朋友有多少对?

具体思路:注意一个地方,朋友关系具有传递性,打个比方 t1和t2 变成了亲密的朋友,然后t0 本来和t1是朋友关系,但是和t2不是朋友关系,t1和t2成为朋友之后,t0也就和t2称为朋友了。

(读题还是太慢了。。。。)

AC代码:

 #include<bits/stdc++.h>
using namespace std;
# define inf 0x3f3f3f3f
const int maxn = +;
int vis[maxn][maxn];
int n,m,k;
bool cal(int t1,int t2)
{
int num=;
for(int i=; i<=n; i++)
{
if(vis[t1][i]&&vis[t2][i])
{
num++;
}
}
if(num<k)
return false;
// cout<<t1<<" "<<t2<<endl;
return true;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(vis,,sizeof(vis));
int t1,t2;
scanf("%d %d %d",&n,&m,&k);
for(int i=; i<=m; i++)
{
scanf("%d %d",&t1,&t2);
t1++;
t2++;
vis[t1][t2]=;
vis[t2][t1]=;
}
int flag=;
int num=;
while(flag)//不能一次循环就完事了,还会有经过传递之后成为新朋友的关系。
{
int ans=;
flag=;
for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
if(vis[i][j])
continue;
if(cal(i,j))
{
vis[i][j]=vis[j][i]=;
ans++;
flag=;
}
}
}
num+=ans;
}
printf("%d\n",num);
}
return ;
}

F - Friends ZOJ - 3710(暴力)的更多相关文章

  1. [ACM_暴力] ZOJ 3710 [Friends 共同认识 最终认识 暴力]

    Alice lives in the country where people like to make friends. The friendship is bidirectional and if ...

  2. Educational Codeforces Round 6 F. Xors on Segments 暴力

    F. Xors on Segments 题目连接: http://www.codeforces.com/contest/620/problem/F Description You are given ...

  3. Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力

    http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...

  4. Friends (ZOJ - 3710)

    Problem Alice lives in the country where people like to make friends. The friendship is bidirectiona ...

  5. zoj 3710 Friends

    #include<stdio.h> #include<string.h> ][],h; int main(int argc, char* argv[]) { int t,i,n ...

  6. 浙江大学2015年校赛F题 ZOJ 3865 Superbot BFS 搜索

    不知道为什么比赛的时候一直想着用DFS 来写 一直想剪枝结果还是TLE = = 这题数据量不大,又是问最优解,那么一般来说是用 BFS 来写 int commandi[4] = {1, 2, 3, 4 ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

  8. zoj 1008 暴力枚举求解dfs+优化

    /* 现将相同的合并计数. 再枚举判断是否符合当cou==n*n是符合就退出 */ #include<stdio.h> #include<string.h> #define N ...

  9. poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP

    poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...

随机推荐

  1. DataGridView显示行号-RowPostPaint

    DataGridView控件在显示数据时,我们有时候需要显示行号,以便检索查看方便使用. 但DataGridView默认没有设置显示行号的属性. 此时我们只要在DataGridView的RowPost ...

  2. JDBC学习笔记——PreparedStatement的使用

    PreparedStatement public interface PreparedStatement extends Statement;可以看到PreparedStatement是Stateme ...

  3. Redis分布式锁的实现

    前段时间,我在的项目组准备做一个类似美团外卖的拼手气红包[第X个领取的人红包最大],基本功能实现后,就要考虑这一操作在短时间内多个用户争抢同一资源的并发问题了,类似于很多应用如淘宝.京东的秒杀活动场景 ...

  4. [转帖]VMware Vsphere 6.0安装部署 (一) 总体部署架构

    (一)总体部署架构本教程用于学习目的,力求详尽的介绍安装部署过程和各组件之间的关系,部署过程从最简单的模型开始,系列文章按时间顺序依次展开,每篇介绍一个组件. 开始阶段,按照一台物理服务器,部署所有V ...

  5. 微信 小程序组件 加入购物车全套 one js

    // pages/shop/shop.js Page({ /** * 页面的初始数据 */ data: { carts: [ { teaname: '冠军乌龙茶-150g', image: '../. ...

  6. 为elasticSearch开发c++接口

    一.    ElasticSearch是什么 ElasticSearch是目前开源全文搜索引擎的首选,可以快速存储,搜索和分析海量数据.Stack Overflow,Github等都在使用. Elas ...

  7. canvas技术整理

    canvas技术整理 html <canvas id= "canvas"></canvas> javascript var canvas = documen ...

  8. 一本通1642【例 2】Fibonacci 第 n 项

    1642: [例 2]Fibonacci 第 n 项 sol:挺模板的吧,经典题吧qaq (1) 1 0    *     1 1     =   1 1 1 0 (2) 1 1    *     1 ...

  9. MT【76】直线系

    解答 :答案是3,4.

  10. 【转】I2C总线协议

    I2C总线(Inter Integrated-Circuit)是由PHILIPS公司在上世纪80年代发明的一种电路板级串行总线标准,通过两根信号线——时钟线SCL和数据线SDA——即可完成主从机的单工 ...