Friends ZOJ - 3710(暴力)

Peace and Friendship 关于和平与友谊的一个ppt,自己亲手制作,敬请放心使用。 立即下载


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 ithfriendship 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.

<h4< dd="">
Output

For each case, print one line containing the answer.

<h4< dd="">
Sample Input

3
4 4 2
0 1
0 2
1 3
2 3
5 5 2
0 1
1 2
2 3
3 4
4 0
5 6 2
0 1
1 2
2 3
3 4
4 0
2 0

<h4< dd="">
Sample Output

2
0
4
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int vis[109][109];
vector<int>a[109];
int is_NewFriend(int u,int v,int k){
    int i,j;
    int commond = 0;
    for(i = 0; i < a[u].size(); i++){
        for(j = 0; j < a[v].size(); j++){
            if(a[u][i] == a[v][j]){
                commond++;
                break;
            }
        }
        if(commond >= k){
            return 1;
        }
    }
    if(k == 0)return 1;//注意!!!!!当k=0并且u没有朋友,这个时候应该也返回1
    return 0;
}
int main(){
    int t;
    cin >> t;
    while(t--){
        int n,m,k;
        cin >> n >> m >> k;
        int i,j;
        memset(vis,0,sizeof(vis));
        for(i = 0; i < 109; i++){
            a[i].clear();
        }
        for(i = 0; i < m; i++){
            int u,v;
            cin >> u >> v;
            vis[u][v] = 1;
            vis[v][u] = 1;
            a[u].push_back(v);
            a[v].push_back(u);
        }
        int sum = 0;
        while(1){
            int flag = 0;
            for(i = 0; i < n; i++){
                for(j = i+1; j < n; j++){
                    if(!vis[i][j]){
                        if(is_NewFriend(i,j,k)){
                            a[i].push_back(j);
                            a[j].push_back(i);
                            vis[i][j] = 1;
                            vis[j][i] = 1;
                            sum++;
                            flag = 1;
                        }
                    }
                }
            }
            if(!flag)
                break;
        }
        cout << sum << endl;
    }
    return 0;
}


My Country and My People PDF版My Country and My People。 立即下载

相关推荐

《老友记英语笔记》电子书.rar

喜欢老友记的朋友可以看看这个笔记!个人的私藏拿出来和大家分享!

ZOJ - 3710 Friends

题目链接 题意:有n个人和m对朋友,其中两个人如果有k个共同好友,那么这两个人在一段时间之后会成为好友。 题记:题目给出的是足够的时间,那么就要一直跟新,直到没有两个人可以成为好友为止。用类似邻接矩阵的方式存下两个人的关系。a[i][j]表示i个j是好友,由于好友是双向的,所以a[j][i]也要存。 之后枚举所有人,然后记录下两个人之间有多少个共同好友,超过k个时要记录下两个人成为好友。 #inc...

moyangxian 197

华为路由器静态路由配置实战:从零搭建企业级网络环境(含常见错误排查)

本文以真实企业组网案例为基础,详细解析华为路由器静态路由的实战配置流程。内容涵盖从网络拓扑规划、IP地址分配到具体的`ip route-static`命令配置,并重点讲解了缺省路由、浮动路由等进阶应用。文章还提供了系统化的排错指南,帮助网络工程师规避回程路由缺失、子网掩码错误等常见问题,是掌握企业级网络搭建与维护的实用指南。

weixin_29313817的博客 89

Friends----暴力枚举

Friends Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less than 

bless295的博客 391

AC7811无感FOC实战:从开环到闭环的电机控制调试全记录

本文详细记录了基于国产AC7811芯片实现无感FOC电机控制的全过程。从硬件软件环境搭建、开环I/F启动调试,到滑模观测器参数整定,再到平滑切入闭环及双环PID调节,提供了完整的实战步骤与参数调试心法。文章重点分享了无感控制从开环到闭环切换的关键技巧与常见问题排查清单,为工程师提供了一份避坑指南。

kotlin6android的博客 713

右腿驱动电路设计:从共模干扰原理到生物电采集实战

在生物电信号采集领域,共模干扰是影响测量精度的核心挑战之一,其本质源于环境电磁场通过容性耦合在人体表面产生的感应电流。根据欧姆定律,由于人体组织阻抗的不均衡性,共模电流会在不同测量点产生差异化的压降,从而转化为难以滤除的差分噪声。为解决这一问题,右腿驱动技术应运而生,它通过负反馈原理主动抵消干扰,显著提升系统的共模抑制比。该技术广泛应用于心电图、脑电图等医疗电子设备中,是确保微弱生理信号质量的关键环节。本文结合工程实践,深入剖析了右腿驱动电路中的仪表放大器选型、反馈环路稳定性设计以及PCB布局布线要点,为高

weixin_31476015的博客 440

浙大OJ刷题1002

浙大OJ刷题1002浙大OJ刷题1002原题地址题目 Fire Net我的答案总结 浙大OJ刷题1002 原题地址 1002:Fire Net 题目 Fire Net Time Limit: 2000 msMemory Limit: 65536 KB Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each repre

One_punchman_zxl的博客 706

八路抢答器____一个作品的制作思路

学习了解到一个产品制作完全由一个人去采购,设计,仿真,画PCB。不光是需求的分析还有实现功能时如何搭建电路,和给出一个简单高效的设计方法也是至关重要的。

weixin_73690807的博客 1520

ZOJ--3710--Friends--二维数组模拟建立关系

题目链接https://vjudge.net/problem/ZOJ-3710 题目大意是输入朋友关系对,双方拥有共同朋友达到数量k之后可以变成朋友。求一段时间后有多少对新的朋友对关系建立起来。 要点: 1、建立friends[from][to]二维数组存储关系对。 2、注意新建立的朋友关系可能会连锁反应建立更多的好友关系。 代码如下: #include #include us

话歪之地的博客 399

《RT-Thread入门与实战》第1章:RT-Thread概述与核心优势

2006年由熊谱翔发起2017年成立上海睿赛德电子科技公司2021年成为国内首个通过ISO 26262 ASIL-D认证的RTOS。

2301_79143213的博客 984

Megatron-LM中的TP、PP、DP、SP、CP并行

SP主要优化的是激活内存,它沿序列维度切分部分激活,适用于较短序列并行。CP主要解决的是长序列的显存问题,它沿序列维度切分所有激活和输入,并且对注意力机制也进行并行处理。二者可以组合使用,特别是当 TP > 1 并且需要处理长序列时,通过启用 SP 和 CP 可以最大化地优化内存使用和加速计算。

u013250861的博客 860

Friends

Alice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less thankfriends in common, they will become friends in several days. Cur...

weixin_30753873的博客 174

锐明技术Crocus系统 DeviceState.do SQL注入漏洞复现

锐明技术Crocus系统 DeviceState.do 接口存在SQL注入漏洞,经过身份验证的远程攻击者除了可以利用SQL注入漏洞获取数据库中的信息(例如,管理员后台密码、站点的用户个人信息)之外,甚至在高权限的情况可向服务器中写入木马,进一步获取服务器系统权限。

0xSec 452

ZOJ 3710 Friends 暴力

Description Alice lives in the country where people like to make friends. The friendship is bidirectional and if any two person have no less than kfriends in common, they will become friends in sev

聂小白的专栏 646

28.Anaconda安装jupyter notebook、jupyterlab及体验

手贱,不小心将Anaconda自带得jupyter给卸载了,没法子了查了好多资料都比较麻烦,所以自己摸索着重新安装,记录一下心得。说明:Anaconda没有加入环境变量,Anaconda官方建议不要将Anaconda加入环境变量,这就意味着他和python是可以共存的。

迷逝 5025

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

ZOJ Problem Set - 3710 Friends(暴力)

ZOJ Problem Set - 3710 Friends

NickJudy的博客 952

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

ZOJ - 3710 Friends 暴力

题目: 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...

zamaochick的博客 166

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

ZOJ 3710 Friends(暴力)

Description Alice livesin the country where people like to make friends. The friendship isbidirectional and if any two person have no less than kfriends in common, they will become friends in sever

Misdom_Tian_Ya的专栏 576

ZOJ-3710-Friends【10th浙江省赛】【暴力】

ZOJ-3710-Friends

Linoy 1028

ZOJ 3710 Friends(暴力)

暴力判断就行了 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define mt(a) memset(a,0,sizeof (a)) #define fl(a,b,c) fill(a

宝树啊宝树 572

ZOJ 3710 Friends(暴力或map)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3710 题意:给你n个人,m对朋友关系,如果两个人的公共好友超过k人,那他们可以成为新的朋友,问经过一段“”足够长的时间后“, 新产生了多少对朋友关系? 思路:题目数据量较小,可以直接暴力,也可以用下stl #include <cstdio...

Tongqi 648

带技巧的暴力-ZOJ 3710 [Friends

#include #include #include #include #include #include #include using namespace std; int map[105][105]; int main() { int i,j,t,n,m,k,p,cun,q,countt,a,b,flag; scanf("%d",&t); for (q=1;q<=

缺氧 550

F - Friends ZOJ - 3710(暴力)

题目链接:https://cn.vjudge.net/contest/280949#problem/F 题目大意:给你n个人,然后给你m个关系,每个关系输入t1, t2 .代表t1和t2是朋友关系(双向关系)。然后输入一个k,代表两个人是亲密的朋友关系的话,就至少有k个共同的朋友,然后问你题目中这样的朋友有多少对? 具体思路:注意一个地方,朋友关系具有传递性,打个比方 t1和t2 ...

diaomeijiao3430的博客 196

ZOJ 3710 Friends

题目链接:ZOJ 3710 Friends 数据范围只有100,暴利可解,不过用vecto

fobdddf的专栏 644

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

    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 day...

weixin_33859844的博客 159
上一篇: 博弈论模板
下一篇: In 7-bit ZOJ - 3713(进制操作转换)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值