2012年浙大: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 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.
- 输入:
-
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.
- 输出:
-
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.
- 样例输入:
-
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
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
- 样例输出:
-
2
AAA 3
GGG 3
0
- 来源:http://ac.jobdu.com/problem.php?pid=1446
- 题意:给定一组电话单,若一群人中(cluster,大于2)所通话时间总和大于阈值(threthold)k,则他们属于一个团伙(gangs),团伙中与其他人通话时间总和最大的人是head。输出团伙数目,按字典序输出各个团伙的head, 以及团伙中的人数。
#include<iostream>
#include<string>
#include<map>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=;
map<string,int> Hash;
int num;
map<int,string> Re;
map<string,int> Count;
vector<string> vec;
int n,k;
int mp[MAXN][MAXN];
int Encode(string s)
{
if(Hash[s]==)
{
num++;
Hash[s]=num;
return num;
}
else return Hash[s];
}
int mx,node,gangs,sum;
int vis[MAXN];
void dfs(int u)
{
vis[u]=;gangs++;
int s=;
for(int i=;i<=num;i++)
{
if(mp[u][i]!=)
{
sum+=mp[u][i];
s+=mp[u][i];
if(!vis[i])
{
dfs(i);
}
}
}
if(s>mx)
{
mx=s;
node=u;
}
}
int main()
{
while(cin>>n>>k)
{
Hash.clear();
Re.clear();
vec.clear();
Count.clear();
memset(vis,,sizeof(vis));
num=;
memset(mp,,sizeof(mp));
for(int i=;i<n;i++)
{
string no1,no2;
int time;
cin>>no1>>no2>>time;
int u=Encode(no1);
int v=Encode(no2);
Re[u]=no1;
Re[v]=no2;
mp[u][v]+=time;
mp[v][u]+=time;
}
for(int i=;i<=num;i++)
{
if(!vis[i])
{
gangs=;
mx=;
sum=;
dfs(i);
sum/=;
if(gangs>=&&sum>k)
{
string no=Re[node];
Count[no]=gangs;
vec.push_back(no);
}
}
} sort(vec.begin(),vec.end());
cout<<vec.size()<<endl;
for(int i=;i<vec.size();i++)
{
string no=vec[i];
cout<<no<<" "<<Count[no]<<endl;
} } return ;
}
2012年浙大:Head of a Gang的更多相关文章
- 2012年浙大:Sharing
题目描述: To store English words, one method is to use linked lists and store a word letter by letter. T ...
- 2012年浙大:Hello World for U
题目描述: Given any string of N (>=5) characters, you are asked to form the characters into the shape ...
- 九度OJ 1446 Head of a Gang -- 并查集
题目地址:http://ac.jobdu.com/problem.php?pid=1446 题目描述: One way that the police finds the head of a gang ...
- Windows server 2012 添加中文语言包(英文转为中文)(离线)
Windows server 2012 添加中文语言包(英文转为中文)(离线) 相关资料: 公司环境:亚马孙aws虚拟机 英文版Windows2012 中文SQL Server2012安装包,需要安装 ...
- Windows Server 2012 NIC Teaming介绍及注意事项
Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...
- 1.初始Windows Server 2012 R2 Hyper-V + 系统安装详细
干啥的?现在企业服务器都是分开的,比如图片服务器,数据库服务器,redis服务器等等,或多或少一个网站都会用到多个服务器,而服务器的成本很高,要是动不动采购几十台,公司绝对吃不消的,于是虚拟化技术出来 ...
- 0.Win8.1,Win10,Windows Server 2012 安装 Net Framework 3.5
后期会在博客首发更新:http://dnt.dkill.net 网站部署之~Windows Server | 本地部署:http://www.cnblogs.com/dunitian/p/482280 ...
- windows 2012 r2 can't find kb2919355
问题 解决: 1.手动安装了 Windows8.1-KB2919442-x64 2.手动下载 KB2919355 更新成功 Turns out to have been a result ...
- Windows Server 2012 磁盘管理之 简单卷、跨区卷、带区卷、镜像卷和RAID-5卷
今天给客户配置故障转移群集,在Windows Server 2012 R2的系统上,通过iSCSI连接上DELL的SAN存储后,在磁盘管理里面发现可以新建 简单卷.跨区卷.带区卷.镜像卷.RAID-5 ...
随机推荐
- C++第4次实验(提高班)—继承和派生1
从项目2和项目3中选1题作为实验.剩下2题写成作业. [项目1 - 龙三] 请在以下程序的横线处填上适当内容,以使程序完整,并使程序的输出为: Name: 龙三 Grade: 19 #include ...
- PowerBuilder -- 条码打印
# 使用ocx控件 使用微软的MSBCODE9.OCX,但是注册老不成功,需要安装office之后才能注册成功,不知道有没有好的处理方法?? # 使用字体 字体下载:http://download.c ...
- python opener代理
链接:http://www.jb51.net/article/46495.htm https://www.cnblogs.com/cunyusup/p/7341829.html
- N皇后问题算法
N皇后问题的两种主要算法是试探回溯法和位运算法.前一种是经典算法,后一种是目前公认的最高效算法,后者比前者效率提高了至少一个数量级.很多问题可以借鉴位运算的思想. 以下是转载的我认为写的比较好的一篇N ...
- AWS:2.根设备类型、EC2生命周期状态、User Data
主要内容 1.根设备类型 linux: /dev/sda1 windows: 系统盘 2.实例生命周期 生命周期状态:停止.终止.重启 3.用户数据(UserData) 实例在初始化,运行之前给定的用 ...
- 基于Flume的美团日志收集系统 架构和设计 改进和优化
3种解决办法 https://tech.meituan.com/mt-log-system-arch.html 基于Flume的美团日志收集系统(一)架构和设计 - https://tech.meit ...
- 《ASP.NET4从入门到精通》学习笔记2
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/dongdongdongJL/article/details/37610807 <ASP.N ...
- 各种python 函数參数定义和解析
python 中的函数參数是赋值式的传递的,函数的使用中要注意两个方面:1.函数參数的定义过程,2.函数參数在调用过程中是怎样解析的. 首先说一下在python 中的函数调用过程是分四种方式的.这里且 ...
- redux和mobx比较(一)
Redux vs Mobx 那么具体到这两种模型,又有一些特定的优缺点呈现出来,先谈谈 Redux 的优势: 数据流流动很自然,因为任何 dispatch 都会导致广播,需要依据对象引用是否变化来控制 ...
- win7下搭建nginx+php的开发环境(转)
在win7下用的是IIS做web服务器,但近来因项目需求的原因,需要在服务器遇到404错误的时候自动做转向(不是在客户端的跳转,而是在服务器收到客户端请求去某目录下读取文件返回时,如果发现目录或目录下 ...