F - Friends ZOJ - 3710(暴力)
题目链接: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(暴力)的更多相关文章
- [ACM_暴力] ZOJ 3710 [Friends 共同认识 最终认识 暴力]
Alice lives in the country where people like to make friends. The friendship is bidirectional and if ...
- Educational Codeforces Round 6 F. Xors on Segments 暴力
F. Xors on Segments 题目连接: http://www.codeforces.com/contest/620/problem/F Description You are given ...
- Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力
http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...
- Friends (ZOJ - 3710)
Problem Alice lives in the country where people like to make friends. The friendship is bidirectiona ...
- zoj 3710 Friends
#include<stdio.h> #include<string.h> ][],h; int main(int argc, char* argv[]) { int t,i,n ...
- 浙江大学2015年校赛F题 ZOJ 3865 Superbot BFS 搜索
不知道为什么比赛的时候一直想着用DFS 来写 一直想剪枝结果还是TLE = = 这题数据量不大,又是问最优解,那么一般来说是用 BFS 来写 int commandi[4] = {1, 2, 3, 4 ...
- 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 ...
- zoj 1008 暴力枚举求解dfs+优化
/* 现将相同的合并计数. 再枚举判断是否符合当cou==n*n是符合就退出 */ #include<stdio.h> #include<string.h> #define N ...
- 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< ...
随机推荐
- Spring sprint @ ninth day
时间 日期 地点 工作 20:05 5.20 九实 集成网络助手项目 遇到的困难:集成遇到,画了好久的rc文件,编译不了.rc文件也不能复制,还得重画.郁闷!!!
- java实验项目报告
JAVA课程项目报告 题目:利用java实现一个时钟的小程序 姓名:王国梁 班级:计科13-2 学号:201303011200 利用JAVA实现一个时钟的小程序 1 ...
- Leetcode题库——47.全排列II
@author: ZZQ @software: PyCharm @file: permuteUnique.py @time: 2018/11/16 13:34 要求:给定一个可包含重复数字的序列,返回 ...
- Android map转json格式,附上Jackson包下载地址,导入过程
android中的map转json,需要下载jackson包,下载地址: http://www.java2s.com/Code/Jar/j/Downloadjacksonall199jar.htm 下 ...
- 助教日志—请沈航13级同学将GIT地址和CNBLOG地址发到这篇博文的评论中
一.评论形式: 学号 姓名 博客地址 GIT地址 如 2011102456 郑蕊 http://www.cnblogs.com/zhengrui0452/ http://121.42.14.1/Rui ...
- Beta 冲刺 一
团队成员 051601135 岳冠宇 031602629 刘意晗 031602248 郑智文 031602330 苏芳锃 031602234 王淇 照片 项目进展 岳冠宇 昨天的困难 无 今天的进度 ...
- HDU 2015 偶数求和
http://acm.hdu.edu.cn/showproblem.php?pid=2015 Problem Description 有一个长度为n(n<=100)的数列,该数列定义为从2开始的 ...
- Activiti End Event及其派生类使用范例
http://tynerblain.com/blog/2006/08/11/bpmn-end-events-1/ 普通流程完结就用end event,而比如无效卡支付时,就会进入cancel end ...
- CentOS下 NFS的简单使用以及windows 关在linux的NFS存储方法
1. 全部安装的情况下NFS已经安装到服务器上面了,如果没有安装的话 需要使用如下命令进行安装 yum -y install nfs-utils rpcbind 2. 创建需要使用的NFS目录 mkd ...
- Python模块-pandas
目录 数据读取 数据探索 数据清洗 数据清洗 类型转换 缺失值 重复值 值替换 修改表结构 新增列 删除列 删除行 修改列名 数据分组(数值变量) 数据分列(分类变量) 设置索引 排序 数据筛选/切片 ...