PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】
Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop this crime, you are supposed to write a program to detect those suspects from a huge amount of phone call records.
A person must be detected as a suspect if he/she makes more than K short phone calls to different people everyday, but no more than 20% of these people would call back. And more, if two suspects are calling each other, we say they might belong to the same gang. A makes a short phone call to B means that the total duration of the calls from A to B is no more than 5 minutes.
Input Specification:
Each input file contains one test case. For each case, the first line gives 3 positive integers K (≤500, the threshold(阈值) of the amount of short phone calls), N (≤103 10^310
3
) , the number of different phone numbers), and M (≤105 10^510
5
) , the number of phone call records). Then M lines of one day’s records are given, each in the format:
caller receiver duration
where caller and receiver are numbered from 1 to N, and duration is no more than 1440 minutes in a day.
Output Specification:
Print in each line all the detected suspects in a gang, in ascending order of their numbers. The gangs are printed in ascending order of their first members. The numbers in a line must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.
If no one is detected, output None instead.
Sample Input 1:
5 15 31
1 4 2
1 5 2
1 5 4
1 7 5
1 8 3
1 9 1
1 6 5
1 15 2
1 15 5
3 2 2
3 5 15
3 13 1
3 12 1
3 14 1
3 10 2
3 11 5
5 2 1
5 3 10
5 1 1
5 7 2
5 6 1
5 13 4
5 15 1
11 10 5
12 14 1
6 1 1
6 9 2
6 10 5
6 11 2
6 12 1
6 13 1
Sample Output 1:
3 5
6
Note: In sample 1, although 1 had 9 records, but there were 7 distinct receivers, among which 5 and 15 both had conversations lasted more than 5 minutes in total. Hence 1 had made 5 short phone calls and didn’t exceed the threshold 5, and therefore is not a suspect.
Sample Input 2:
5 7 8
1 2 1
1 3 1
1 4 1
1 5 1
1 6 1
1 7 1
2 1 1
3 1 1
Sample Output 2:
None
【声明】
由于此题还未上PAT官网题库,故没有测试集,仅仅是通过了样例,若发现错误,感谢留言指正。
Solution:
判断电话诈骗分子,当一个人与>k个不同的人打短时间【<= 5分钟】通话,且这些人中只有不超过20%的人给回了电话,那么这个人就是诈骗犯;
当相互有通话的诈骗犯是认为同一组;
输出按组内升序,组间按第一个组员升序的格式输出。
使用邻接矩阵记录通过时间【累计通话时间】,然后分别记录每个人满足要求的打出的电话人数以及回电话的人数,最后将相互通话的嫌疑犯视为一组。
注重细节哦。
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
int k, n, m, t;
cin >> k >> n >> m;
vector<int>call(n + , ), back(n + , );//短电话打出去的记录和这些人打回进来的记录
vector<vector<int>>v(n + , vector<int>(n + , ));//电话记录,记住记录的是累计的通话时间
while (m--)
{
int a, b, c;
cin >> a >> b >> c;
v[a][b] += c;//算累加通话时间的
}
for (int i =; i <= n; ++i)
{
for (int j = ; j <= n; ++j)
{
if (v[i][j]> && v[i][j] <= )//这通话时间算是短电话
{
++call[i];//计算i打出去的人数
if (v[j][i] > )//这是j回给了i的
++back[i];//计算回给i的人数
}
}
}
vector<int>suspect, team(n + , );//统计诈骗犯的人数和初始化他们的团队号
for (int i = ; i <= n; ++i)
{
if (call[i] > k && call[i] >= back[i]*)//打出去的人数大于阈值k,回电话的人数不多于打出去的20%,注意
{
team[i] = i;//用来算同谋的
suspect.push_back(i);
}
}
for (int i = ; i < suspect.size(); ++i)//这里虽然是双重循环,但是诈骗犯的数量级很小的,所以这里应该不会超时间的,当然,超了的话,就用DFS即可
for (int j = i + ; j < suspect.size(); ++j)
if (v[suspect[i]][suspect[j]] > && v[suspect[j]][suspect[i]] > )//这两个诈骗人相互打过电话
team[suspect[j]] = team[suspect[i]];
map<int, vector<int>>res;
for (int i = ; i <= n; ++i)
if (team[i] > )
res[team[i]].push_back(i);//将属于同一伙的诈骗犯放一组
if (suspect.size() == )
printf("None");
else
{
for (auto ptr = res.begin(); ptr != res.end(); ++ptr)
{
for (int i = ; i < ptr->second.size(); ++i)//由于遍历是从小到大的,所以不用排序
printf("%s%d", i == ? "" : " ", ptr->second[i]);
printf("\n");
}
}
return ;
}
PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】的更多相关文章
- PAT甲级【2019年3月考题】——A1157 Anniversary【25】
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...
- PAT甲级【2019年9月考题】——A1164 DijkstraSequence【30】
7-4 Dijkstra Sequence (30 分) Dijkstra's algorithm is one of the very famous greedy algorithms. It is ...
- PAT甲级【2019年9月考题】——A1163 PostfixExpression【25】
7-3 Postfix Expression (25 分) Given a syntax tree (binary), you are supposed to output the correspon ...
- PAT甲级【2019年9月考题】——A1162 MergingLinkedLists【25】
7-2 Merging Linked Lists (25 分) Given two singly linked lists L 1 =a 1 →a 2 →...→a n−1 →a n L1=a1→a ...
- PAT甲级【2019年9月考题】——A1160 Forever【20】
7-1 Forever (20 分) "Forever number" is a positive integer A with K digits, satisfying the ...
- PAT甲级【2019年3月考题】——A1159 Structure_of_a_BinaryTree【30】
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...
- PAT甲级【2019年3月考题】——A1156 SexyPrimes【20】
Sexy primes are pairs of primes of the form (p, p+6), so-named since “sex” is the Latin word for “si ...
- PAT甲级2019冬季考试题解
A Good In C纯模拟题,用string数组读入数据,注意单词数量的判断 #include<bits/stdc++.h> using namespace std; ; ][]; in ...
- PAT甲级题解-1097. Deduplication on a Linked List (25)-链表的删除操作
给定一个链表,你需要删除那些绝对值相同的节点,对于每个绝对值K,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...
随机推荐
- Docker配置远程访问
近来学习Docker部署微服务,需要配置Docker的远程访问,由于实际环境和学习资料有出入,尝试着根据网上搜索的一些相关资料进行配置,未能成功.最终通过自己摸索,成功配置Docker远程访问.现和大 ...
- Java并发编程:Concurrent锁机制解析
Java并发编程:Concurrent锁机制解析 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: # ...
- 【Python】Python实现Excel用例直接导入testlink-UI界面小工具
1.写在前面 testlink上传用例一种方法是excel转换为xml,然后再用xml上传,还有一种是调用api进行上传.最开始写了个转换工具,是将excel转换为xml,然后在testlink里上传 ...
- linq函数All,Any,Aggregate说明
int[] arrInt; arrInt = ,,,,,,}; );// 所有元素都满足条件,false );// 有任一元素满足条件,true , , , , , , , , }; var quer ...
- shell脚本从入门到精通(中级)之提高篇
shell 脚本入门到精通(中级) 一.shell 脚本的执行 二.输出格式化 三.数据类型 四.重定向 五.变量 一.shell 脚本的执行 1. 脚本执行的4种方法 $ ls /tmp/test. ...
- MySQL语句优化方法(简单版)
基础回顾: sql语句是怎么样运行的? 一般来说,客户端发送sql语句到数据库服务器——数据库服务器进行运算并返回结果——客户端显示sql语句运行结果. 在本地运行时以workbench为例,客户端为 ...
- python3使用print打印带颜色的字符串
一.实现过程 终端的字符颜色是用转义序列控制的,是文本模式下的系统显示功能,和具体的语言无关 转义序列是以ESC开头,即用\033来完成(ESC的ASCII码用十进制表示是27,用八进制表示就是033 ...
- SCM
scm即软件配置管理. 软件配置管理(SCM)是指通过执行版本控制.变更控制的规程,以及使用合适的配置管理软件,来保证所有配置项的完整性和可跟踪性,配置管理是对工作成果的一种有效保护. SCM(Sof ...
- Jade To Pug过程中的一个小问题
最近在使用jade+express+typescript搭建一个博客项目,在使用jade-bootstrap项目时出现了一个问题 在使用其中的carousel时,发现其中的变量并没有转义 +carou ...
- python模块之jinja2 ,shutil
一 jinja2 用来给python提供html语法的模块 安装 pip install jinja2 使用 from jinja2 import Template def html_output(p ...