【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个人的 ...
随机推荐
- Django - 后台admin不显示带auto_now, auto_now_add选项的字段
https://stackoverflow.com/questions/6386172/datetimefield-doesnt-show-in-admin-system 解决办法 class Rat ...
- 6_10 下落的树叶(UVa699)<二叉树的DFS>
每年到了秋天树叶渐渐染上鲜艳的颜色,接着就会落到树下来.假如落叶发生在二叉树,那会形成多大的树叶堆呢?我们假设二叉树中的每个节点所落下的叶子的数目等于该节点所储存的值.我们也假设叶子都是垂直落到地面上 ...
- frp 使用基础笔记
0x01 简介 为什么需要内网穿透? 很多时候从公网访问自己内网的设备是困难的,毕竟自己没有一个独立的IP地址. Frp 服务器进行内网穿透,速度快还十分简单.可以实现很多功能,包括不限于远程桌面,文 ...
- Blockchain资源
程序源码: https://github.com/HuangFJ/pyeth https://www.jianshu.com/p/b72b4eb259b8
- pc和手机点击复制到剪贴板
https://www.cnblogs.com/kevinCoder/p/6144376.html
- python中getpass模块
1 import getpass 2 name = input('请输入你的名字:') 3 passwd = getpass.getpass('请输入你的密码:') 4 print(name) 5 p ...
- Java常用API——Arrays工具类
介绍:Arrays工具类提供了一些可以直接操作数组的方法,以下是一些常用方法: int binarySearch(type[] a, type key):要求数组a元素升序排列,使用二分法搜索key的 ...
- 添加安卓端的User-Agent
将系统换为Android即可 随机UA UA分析网站 Mozilla/5.0 (Windows NT 6. 4; WOW64) AppleWebKit/537. 36 (KHTML, like Gec ...
- Kubernetes的service资源介绍
service 三种工作模式:userspace.iptables.ipvs 删除手动创建的service [root@master ~]# kubectl delete svc redis serv ...
- netty实现websocket客户端(附:测试服务端代码)
1,客户端启动类 package test3; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.Unpooled; import ...