PAT1034 Head of a Gang

MTK手机传感器驱动开发避坑指南:从SCP代码大小限制到Overlay加载流程详解 本文详细解析了MTK平台传感器驱动开发中的常见问题,包括SCP代码大小限制、Overlay加载流程及客制化传感器集成。通过实战案例和优化策略,帮助开发者高效解决MTK传感器驱动开发中的技术难题,提升开发效率。 阅读详情

上次三月没满分。。开始准备搞九月了,希望这次能满分吧。3月份的时候英文太差了,看的好累,现在感觉还好了些,看运气了。(其实目前唯一自信的科目只有数学,别的。。都是随缘佛系)。

今天做了这道题。。我就服了,我三月去的时候没做这道,结果三月是题设背景和这题基本一样的题目就是加深复杂了一点。。我当时都看不懂Gang是什么意思。。血崩。

应该是要并查集做,我这边锻炼下模拟能力用STL模拟做了一下也过了,下面是题解(保佑我九月PAT满分。。初试高分(英语过线就好了!!!!))。

One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of all the phone calls made between the two persons. A "Gang" is a cluster of more than 2 persons who are related to each other with total relation weight being greater than a given threthold K. In each gang, the one with maximum total weight is the head. Now given a list of phone calls, you are supposed to find the gangs and the heads.

Input Specification:

Each input file contains one test case. For each case, the first line contains two positive numbers N and K (both less than or equal to 1000), the number of phone calls and the weight threthold, respectively. Then N lines follow, each in the following format:

Name1 Name2 Time

where Name1 and Name2 are the names of people at the two ends of the call, and Time is the length of the call. A name is a string of three capital letters chosen from A-Z. A time length is a positive integer which is no more than 1000 minutes.

Output Specification:

For each test case, first print in a line the total number of gangs. Then for each gang, print in a line the name of the head and the total number of the members. It is guaranteed that the head is unique for each gang. The output must be sorted according to the alphabetical order of the names of the heads.

Sample Input 1:

8 59
AAA BBB 10
BBB AAA 20
AAA CCC 40
DDD EEE 5
EEE DDD 70
FFF GGG 30
GGG HHH 20
HHH FFF 10

Sample Output 1:

2
AAA 3
GGG 3

Sample Input 2:

8 70
AAA BBB 10
BBB AAA 20
AAA CCC 40
DDD EEE 5
EEE DDD 70
FFF GGG 30
GGG HHH 20
HHH FFF 10

Sample Output 2:

0

题目意思:给一堆通话记录,从这些通话记录里面我们可以推断知道哪些人是一伙的,判断是不是形成了一个团伙,也就是小团队里面互有联系,而且通话时间总和超过给定值,同时人数要大于2....如果形成了团伙,同时找出头目。就是团伙中通话时间最长的那个,然后输出一下,保证头目只有一个,按头目的字母序输出一下即可。

思路:理论上要并查集的。但是心血来潮模拟了一下,还是给模拟出来了。占空间会很大。有种OOP的思想在里面。

就是先建立同伙结构体:成员,是否有效的标志,总的那个通话时间,头目(后来发现并不用,可以删掉).

然后是两个map,key均为string即成员姓名,恩,很简单了。其中一个map指向gflag,为所属团伙的下标+1,如果没有团伙归属那就是0,然后另一个map指向总时间,表示这个人总的通话时间。

后面的思路就simple了哈哈,用一个vector存放gangs,每次读入一条通话记录的时候,只要检查这两个人的名字所指向的gflag情况就行了,分以下几种情况:

1.两个人都没有归属的团伙,也就是两个gflag都是0:

这个时候很显然的就是要new 一个团伙出来,然后把成员加进去,标志初始化为0,0表示有效,通话时间对应改成的当前读进来的时间。然后将这个gang加进数组,把对应的这两个人对应的gflag初始化成这个刚进去的gang的下标,也就是当前数组的尺寸.

上面几步操作,顺序无所谓。

2.两个人有一个已经有团伙了,另一个还没有。

这个比上面还要简单,直接把没有的那个加到有的那个里面去,时间和成员更新一下就完事了。

3.两个人都有团伙了,且是同一个。

这个很明显了,直接把时间加上就ok。

4.两个人都有团伙了,但不是同一个。

这个略微复杂,但也不是很难,显而易见的就是把其中一个合并过去。为了时间考虑我们选择把人数少的合到人数多的地方去,然后我们考虑怎么合,第一步肯定是小团伙的成员遍历一遍并且加到另一个团伙那边去,在这同时我们要把这里小团伙成员的gflag都指向那个大团伙不就搞定了?但是不要忘记时间!!对应的要把小团伙的总时间加过去的同时还要把这条记录的时间加过去!!

也许你会问,那我那个小团伙怎么办erase吗,首先,肯定不能erase,因为你一erase,你的那些gflag全乱了啊,肯定不行的,那怎么办,这就是我为什么设置个团伙有效的标志了,直接小团伙有效标志置为1,无效,然后遍历的时候不是0的全部不看就是了。

这样就读入完数据了,剩下就是一些正常的处理这里就不讲了,没什么好讲,下面是代码。

当然,肯定是并查集方便,这只是读书之余的一种休闲。

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<time.h>
#include<math.h>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string.h>
using namespace std;
struct gang {
	set<string> mem;//成员
	int time;//通话总时间
	string head;//头目,弃用
	int de;//有效标志,0有效,1无效
};
struct resu {
	string headd;//头目名字
	int mems;//团伙人数
};
map<string, int> gflag;//纪录当前人所属的团伙标号=下标+1
map<string, int> ptime;//记录当前人总的通话时间,便于后面比较
vector<gang> gangs;//团伙
void merge(int a,int b,int t){
	for (auto i = gangs[b].mem.begin(); i != gangs[b].mem.end(); i++) {
		gflag[*i] = a+1;
		gangs[a].mem.insert(*i);
	}
	gangs[a].time += gangs[b].time;
	gangs[a].time += t;
	gangs[b].de = 1;
}
bool sss(resu a, resu b) {
	return a.headd < b.headd;
}
int main()
{
	int n, m;
	scanf("%d %d", &n,&m);
	for (int i = 0; i < n; i++) {
		string a, b; int t;
		cin >> a >> b >> t;
		ptime[a] += t;
		ptime[b] += t;
		if (gflag[a] == 0 && gflag[b] == 0) {
			gang tmp;
			tmp.time = 0;
			tmp.time += t;
			tmp.mem.insert(a);
			tmp.mem.insert(b);
			tmp.de = 0;
			gflag[a] = gangs.size()+1;
			gflag[b] = gangs.size() + 1;
			gangs.push_back(tmp);
		}
		else if (gflag[a] == 0 && gflag[b] != 0) {
			gangs[gflag[b] - 1].time += t;
			gangs[gflag[b] - 1].mem.insert(a);
			gflag[a] = gflag[b];
		}
		else if (gflag[a] != 0 && gflag[b] == 0) {
			gangs[gflag[a] - 1].time += t;
			gangs[gflag[a] - 1].mem.insert(b);
			gflag[b] = gflag[a];
		}
		else {
			if (gflag[a] == gflag[b]) {
				gangs[gflag[a] - 1].time += t;
			}
			else {
				int a1, b1;
				if (gangs[gflag[a] - 1].mem >= gangs[gflag[b] - 1].mem) {
					a1 = gflag[a] - 1;
					b1 = gflag[b] - 1;
				}
				else {
					a1 = gflag[b] - 1;
					b1 = gflag[a] - 1;
				}
				merge(a1, b1,t);
			}
		}
	}
	vector<resu> res;
	for (int i = 0; i < gangs.size(); i++) {
		if (gangs[i].de == 0 && gangs[i].time > m&&gangs[i].mem.size()>2) {
			string hee;
			int max = 0;
			for (auto j = gangs[i].mem.begin(); j != gangs[i].mem.end(); j++) {
				if (ptime[*j] > max) {
					max = ptime[*j];
					hee = *j;
				}
			}
			resu ttt;
			ttt.headd = hee;
			ttt.mems = gangs[i].mem.size();
			res.push_back(ttt);
		}
	}
	printf("%d\n", res.size());
	sort(res.begin(), res.end(), sss);
	for (int i = 0; i < res.size(); i++) {
		cout << res[i].headd << " " << res[i].mems << endl;
	}
	return 0;
}

 

MPC模型预测控制实战:从理论到代码实现(Python示例) 本文详细介绍了MPC模型预测控制的实战应用,从理论到Python代码实现。通过构建系统模型、预测方程、优化问题及约束处理,展示了如何实现一个完整的MPC控制器。文章还提供了水箱液位控制的应用案例,帮助读者掌握MPC在工业控制中的实际应用。 阅读详情

相关推荐

MFC工具栏增加EditBox和Button

1. 在资源视图中增加EditBox, Button控件,ID分别为ID_EDIT_SEED, ID_BTN_SEED 2. 在CMainFrame中增加成员变量 CMFCToolBarEditBoxButton *m_editSeed; CMFCToolBarButton *m_btnSeed; 3. 在CMainFrame::OnCreate中创建控件 m_editSeed = new CMFCToolBarEditBoxButton(ID_EDIT_SEED, GetCmdMgr()-&.

学习是为了探索这个世界的本质 802

【PAT(甲级)】1034 Head of a Gang

解题思路: 就是一个并查集,加一个权重判断的问题。可以用bfs来遍历所有节点,然后找到权重最大的节点就是帮派的头目。其中的难点就在于,节点不是常规的数字,而是string类型的名字。我的解决方法就是直接用map给他们匹配一下。...

weixin_55202895的博客 262

LWIP协议栈在STM32H7上的内存优化实战:如何用32KB RAM实现稳定千兆以太网通信

本文深入探讨了在STM32H7微控制器上,如何通过内存优化策略,在仅32KB的D2 SRAM中稳定运行LWIP协议栈以实现千兆以太网通信。文章详细分析了STM32H7的内存架构、LWIP的内存消耗瓶颈,并提供了从描述符表与PBUF池精确分配、链接脚本修改到MPU区域划分的一整套实战优化方案,旨在解决大数据量传输卡死等常见配置问题。

gg901的博客 603

【PAT甲级】1034 Head of a Gang (30 分)

PAT甲级1034题解

小染的学习笔记 927

深入解析Panfrost驱动:Mali-GPU开源驱动的架构与实现

本文深入解析了Panfrost驱动作为Mali-GPU开源驱动的架构与实现。从诞生背景到硬件架构演进,详细介绍了Panfrost如何突破ARM闭源策略,实现全栈支持。文章还探讨了驱动设计中的关键技术挑战与性能优化策略,为开发者提供了实用的编译部署指南和性能调优方法。

weixin_30790841的博客 552

GX WORKS2通过交换机连接PLC的方法

三菱PLC连接方法的分享

weixin_64927621的博客 3618

「1034」Head of a Gang

One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call betweenAandB, we say thatAandBis related. The weight of a relation is define...

weixin_52435933的博客 236

sqoop抽取mysql的数据到hive表里面,字段内容被自动截取,导致字段不全的问题解决

今天央视重新转播NBA,写篇博客纪念一下这个重要的日子,湖人的表现就呵呵了!!!! 强行转到博客的主题来 mysql的字段属性:该字段能存下的值比如:“山东” `province` varchar(3) NOT NULL COMMENT '省份' 用sqoop sqoop import --connect "jdbc:mysql://xxxxxx:3306/xxxxxx?tinyInt1isBit=false&zeroDateTimeBehavior=convertToNull..

放肆桀骜 963

1034. Head of a Gang (30)

【代码】1034. Head of a Gang (30)

2401_88085478的博客 1039

基于FFT的阵列方向图快速计算公式推导

因为自己毕设涉及到阵列方向图综合相关知识,最近阅读了关于方向图综合的相关文献,就其中关于使用FFT计算阵列方向图的方法进行了公式推导。 简介: 自从1965年Colley-Tukey发表快速傅里叶变换[1]论文以来,FFT在许多科学技术领域获得了广泛和成功的应用。在阵列信号处理与雷达信号处理领域,随着科技的发展,对于电尺寸较大的相控阵天线,使用公式按照级数求和计算天线阵列方向图的方法效率甚低,...

qq_38151438的博客 4290

Android逆向分析

Android 逆向开发是指对已发布的 Android 应用进行分析和破解,以了解应用程序的内部工作原理,获取应用程序的敏感信息,或者修改应用程序的行为。Android应用 Java编写的,利用Android SDK编译代码,并并且把所有的数据和资源文件打包成一个APK(Android Package)文件这是一个后缀名为.apk的压缩文件,apk文件中包含了一个Anddroid应用程序的所有内容,是Android平台用于安装应用程序的文件。

qq_51598534的博客 6293

PAT 甲级 1034 Head of a Gang

语雀满了,只能暂时先用优快云来记录一下了。这道题之前看王道书的时候做过一次,当时是照着查并集的思想做的。昨天刷PAT重做的时候,第一时间想到的还是查并集,然后尝试着自己独立去写,发现仅仅用查并集其实还是有很多的坑的。

2301_77209094的博客 169

基于 InceptionNeXt 模块增强的 YOLOv8 模型:针对多尺度目标检测的改进与实现

modules.py。

know_F0727的博客 203

PAT 1034. Head of a Gang

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1034 题解: 代码: #include #include #include #include #include #include #include #include #include using namespace std; #define INF 0x6fffffff map weight

Ted's 游乐园 1660

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

[PAT-A 1034]Head of a Gang

考察图的遍历(DFS) 题目大意:给出若干人之间的通话长度(视为无向边),这些通话将他们分为若干组,每个组的总边权设为改组内的所有通话长度之和,每个人的点权设置为该人参与通话的长度。 给定阈值K,只要一个组的总边权超过K,并且人数超过2,则认为该组为一个Gang,组内点权最大的人为head,求按头目姓名字典顺序从小到达输出每个Gang中的Head和成员人数 思路: 1.使用map<stir...

RegulusF的博客 209

深度学习工具包 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")

PAT A 1034 Head of a Gang

题目要求通过电话记录找出犯罪团伙及其头目。团伙定义为超过2人且总通话时长超过阈值K的连通群体,头目为团伙中总通话时长最多的人。算法使用深度优先搜索(DFS)遍历图的连通块,统计每个团伙的成员数和总时长,最终输出按头目名字排序的结果。样例1中AAA和GGG作为头目各领导3人团伙,而样例2因不满足条件输出0。

whdehcy的博客 605

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

PAT A1034 Head of a Gang

一、题目大意 PAT A1034 给出若干人之间的通话记录,这些通话将他们分成若干组。每个组的总边权值为该组内所有通话的时间之和,每个人的点权为该人参与的通话时间之和。现在只要某个组的总边权值大于一个阈值 k,并且组内人数大于 2,就将该组视为“犯罪团伙(gang)”,该组内点权最大的人视为头目。要求输出“犯罪团伙”的数目,并按头目姓名字典序的方式输出每个“犯罪团伙”的头目姓名和人数。 二、解...

Armstrong的博客 232

【PAT】A1034 Head of a Gang 【并查集】

One way that the police finds the head of a gang is to check people’s phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be t...

elegant coder 1664

PAT 1034 Head of a Gang

一个gang的总通话用时大于k,且人数大于2,gang的head为其中总通话用时最长的人。根据输入求有几个gang,并按字母顺序输出head和人数。 这一题用并查集和图的遍历,比较繁琐,先要求每一个的总通话时长,合并到一个集合后(合并时可以按通话时长选择节点,通话时间长的为被指向的节点),求每一个集合的总通话时长和人数,根据条件判断是否符合条件。 审题不仔细,有一个点错误,后来重新审一遍题,发现head是保证唯一的。 (用时:1:47:36.95) #include<iostream> #inc

Genius_J的博客 228

PAT(Advanced) 1034 Head of a Gang C++实现 并查集 路径压缩

PAT(Advanced) 1034 Head of a Gang 题目链接 1034 Head of a Gang 题目大意 根据通话记录来找到帮派的头目,一个帮派由三个及以上的人组成且其成员之间通话时长大于阈值K 算法思路 根据题意,一个帮派的人在同一个连通分量中,通过并查集,累加连通分量的关系权值和连通分量中的顶点数,找到符合条件的输出头目和人数,并查集合并时将关系权重较大的顶点作为根结点,需要注意的是找到连通分量所属的根结点每次都需要调用find(),否则某些情况会出错 根据题意,输出的名字需要进行

qq_44486439的博客 319

pat甲级1034 Head of a Gang

【代码】pat甲级1034 Head of a Gang。

2303_76815666的博客 1550

PAT 1034 Head of a Gang C++版

PAT 1034 Head of a Gang C++版 1.题意 给出一串用户通话的记录(记录形式是[name1,name2,time])。互相之间有通话关系的算是在同一个团队中。现在让你求出有多少个团伙,并且求出这个团伙中通话最多的人,以及输出这个团伙的总人数。 2.分析 解决这个问题可以使用两种方法,两种方法都较简单。一种是深搜法,一种是并查集法。并查集对于解决这种问题十分适合。所以笔者强烈...

说文科技,做有态度的研究。 718

【PAT】1034 Head of a Gang (30) [graph][dfs]

1034 Head of a Gang (30分) 牛客 1034 Head of a Gang (30分) 测试点3排序后正确 其他测试点…快被整疯了,牛客上可以过PAT过不了 测试点1和2应该是输出0,其他的应该是输出格式问题? #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<string> #include<vector> #include<map> using namespa

马甲都掉光了 229

PAT 甲级 1034  Head of a Gang

1034 Head of a Gang (30 point(s)) One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weig...

漫浸天空的雨色的备忘录~ 1006
上一篇: 分布式配置中心选择
下一篇: SPFA+队列优化与迪杰斯特拉+优先队列(最小堆优化)解一道水题
Tate_Brown
博客等级 码龄9年 39粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值