【PAT甲级】1034 Head of a Gang (30 分)
题意:
输入两个正整数N和K(<=1000),接下来输入N行数据,每行包括两个人由三个大写字母组成的ID,以及两人通话的时间。输出团伙的个数(相互间通过电话的人数>=3),以及按照字典序输出团伙老大的ID和团伙的人数(团伙中通话时长最长的人视为老大,数据保证一个团伙仅有一名老大)。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s,s2;
int x[],y[];
vector<pair<int,int> >edge[];
bool vis[];
int val[];
int mx=;
int pos=;
int ans[];
int num[];
int cnt=;
int c[];
bool visedge[];
int sum2=;
void dfs(int x){
if(!vis[x])
++cnt;
vis[x]=;
for(auto it:edge[x]){
if(visedge[it.second])
continue;
visedge[it.second]=;
if(!vis[it.first]){
++cnt;
vis[it.first]=;
}
val[x]+=c[it.second];
val[it.first]+=c[it.second];
sum2+=c[it.second];
if(val[x]>mx){
mx=val[x];
pos=x;
}
dfs(it.first);
}
}
int main(){
int n,k;
cin>>n>>k;
for(int i=;i<=n;++i){
cin>>s>>s2>>c[i];
x[i]=(s[]-'A')**+(s[]-'A')*+s[]-'A';
y[i]=(s2[]-'A')**+(s2[]-'A')*+s2[]-'A';
edge[x[i]].push_back({y[i],i});
edge[y[i]].push_back({x[i],i});
}
int sum=;
for(int i=;i<=n;++i){
sum2=;
mx=;
pos=;
cnt=;
if(!vis[x[i]])
dfs(x[i]);
if(cnt>&&sum2>k){
ans[pos]=sum2;
num[pos]=cnt;
++sum;
}
}
cout<<sum<<"\n";
for(int i=;i<**;++i)
if(ans[i]){
char alp[];
int tmp=i;
alp[]=tmp//;
tmp%=*;
alp[]=tmp/;
tmp%=;
alp[]=tmp;
for(int j=;j<=;++j){
alp[j]+='A';
cout<<alp[j];
}
cout<<" "<<num[i]<<"\n";
}
return ;
}
【PAT甲级】1034 Head of a Gang (30 分)的更多相关文章
- PAT 甲级 1034 Head of a Gang (30 分)(bfs,map,强连通)
1034 Head of a Gang (30 分) One way that the police finds the head of a gang is to check people's p ...
- pat 甲级 1034. Head of a Gang (30)
1034. Head of a Gang (30) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue One wa ...
- PAT甲级1034. Head of a Gang
PAT甲级1034. Head of a Gang 题意: 警方找到一个帮派的头的一种方式是检查人民的电话.如果A和B之间有电话,我们说A和B是相关的.关系的权重被定义为两人之间所有电话的总时间长度. ...
- pat 甲级 1034 ( Head of a Gang )
1034 Head of a Gang (30 分) One way that the police finds the head of a gang is to check people's pho ...
- PAT 甲级 1064 Complete Binary Search Tree (30 分)(不会做,重点复习,模拟中序遍历)
1064 Complete Binary Search Tree (30 分) A Binary Search Tree (BST) is recursively defined as a bin ...
- PAT 甲级 1053 Path of Equal Weight (30 分)(dfs,vector内元素排序,有一小坑点)
1053 Path of Equal Weight (30 分) Given a non-empty tree with root R, and with weight Wi assigne ...
- PAT 甲级 1038 Recover the Smallest Number (30 分)(思维题,贪心)
1038 Recover the Smallest Number (30 分) Given a collection of number segments, you are supposed to ...
- PAT Advanced 1034 Head of a Gang (30) [图的遍历,BFS,DFS,并查集]
题目 One way that the police finds the head of a gang is to check people's phone calls. If there is a ...
- PAT甲级1034 Head of a Gang【bfs】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805456881434624 题意: 给定n条记录(注意不是n个人的 ...
随机推荐
- VS2017新建或拷贝项目编译时出现:找不到 Windows SDK 版本8.1.请安装所需的版本的 Windows SDK
VS2017新建或拷贝项目编译时出现:找不到 Windows SDK 版本8.1.请安装所需的版本的 Windows SDK 或者在项目属性页的问题解决方案 解决方法: 右击项目解决方案, 选择:重定 ...
- Codeforces Round #577 (Div. 2) 题解
比赛链接:https://codeforc.es/contest/1201 A. Important Exam 题意:有\(n\)个人,每个人给出\(m\)个答案,每个答案都有一个分值\(a_i\), ...
- mui 进度条 隐藏
官方提供的 mui(contanier).progressbar().hide(); 并未起作用,DOM是js动态添加的,结果无法隐藏.(越使用,mui 的坑越多,陆续记录中...) 后使用下面的方法 ...
- Java入门笔记 07-枚举类
介绍:在某些情况下,一个类的对象是有限且固定的,比如季节类,只有四个对象:春夏秋冬.这种实例有限而且固定的类,被称为枚举类.在JDK 5.0及以后,可以使用enum关键字定义枚举类,并且默认继承于ja ...
- Linux - 常用Shell软件
tldr conda dstat htop oh-my-zsh https://github.com/nicolargo/glances neofetch
- Django - 在settings配置终端打印SQL语句
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'console': { 'level': 'DE ...
- css常见问题汇总
1. 如果我想显示两行文字第二行超出部分‘...’? 限制在一个块元素显示的文本的行数. -webkit-line-clamp 是一个 不规范的属性(unsupported WebKit proper ...
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'.
关于以上错误,观察是否缺少了某一项,还要注意书写的顺序 建议这一类配置文件直接复制就好了,不要自己写 <?xml version="1.0" encoding="U ...
- 微信小程序媒体音乐API更新小记,以及音乐外链制作方法
假期开发微信小程序玩的时候发现音乐播放功能,但是教程中的旧版API已经不能成成功打开 官方文档写的很清楚,旧版接口不再维护,使用新版接口,换API后,又出现了新的问题,虽然没有报错信息,但是播放器闪退 ...
- Centos610安装Archiva
安装说明: https://www.cwiki.us/display/ArchivaZH/Linux+Installing+Standalone 1.下载地址 https://archiva.apac ...