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】的更多相关文章

  1. PAT甲级【2019年3月考题】——A1157 Anniversary【25】

    Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...

  2. PAT甲级【2019年9月考题】——A1164 DijkstraSequence【30】

    7-4 Dijkstra Sequence (30 分) Dijkstra's algorithm is one of the very famous greedy algorithms. It is ...

  3. PAT甲级【2019年9月考题】——A1163 PostfixExpression【25】

    7-3 Postfix Expression (25 分) Given a syntax tree (binary), you are supposed to output the correspon ...

  4. 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 ...

  5. PAT甲级【2019年9月考题】——A1160 Forever【20】

    7-1 Forever (20 分) "Forever number" is a positive integer A with K digits, satisfying the ...

  6. 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 ...

  7. 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 ...

  8. PAT甲级2019冬季考试题解

    A Good In C纯模拟题,用string数组读入数据,注意单词数量的判断 #include<bits/stdc++.h> using namespace std; ; ][]; in ...

  9. PAT甲级题解-1097. Deduplication on a Linked List (25)-链表的删除操作

    给定一个链表,你需要删除那些绝对值相同的节点,对于每个绝对值K,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...

随机推荐

  1. python学习第五天--函数进阶

    局部变量与全局变量下面代码中,old_price,rite为全局变量,final_price为局部变量 globals() 声明全局变量,在函数内可修改函数外的变量 内嵌函数:函数当中嵌套函数 闭包: ...

  2. 【问题解决方案】GitHub仓库重构之将某个或某些文件夹移动到其他文件夹内

    仓库重构时遇到的问题,在GitHub页面里好像没有类似的操作按钮? 搜了一下好像要用到一些命令比如rm等,但是我对Linux类的命令不是很熟悉 于是想试试曲线救国,先把远程库的文件pull到本地,在本 ...

  3. art-template补充

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  4. ABP框架按条件导出

    web层 .js导出事件: //导出为excel文档 $('#btn-export').click(function () { //得到查询的参数 var temp = { //这里的键的名字和控制器 ...

  5. 系统INIT 启动脚本的结构/etc/rc.d/init.d/*

  6. 233-基于TMS320C6678+XC7K325T的CPCIe开发平台

    基于TMS320C6678+XC7K325T的CPCIe开发平台 一.板卡概述         该DSP+FPGA高速信号采集处理板由我公司自主研发,包含一片TI DSP TMS320C6678和一片 ...

  7. vue,一路走来(12)--父与子之间传参

    今天想起一直没有记录父组件与子组件的传参问题,这在项目中一直用到. 父向子组件传参 Index.vue父组件中 <component-a :msgfromfa="(positionno ...

  8. 联想笔记本 thinkpad BIOS 超级密码 Supervisor Password 清除 破解 亲测有效 转载地址https://blog.csdn.net/ot512csdn/article/details/72571674

    联想笔记本 thinkpad BIOS 超级密码 Supervisor Password 清除 破解 亲测有效 转载地址https://blog.csdn.net/ot512csdn/article/ ...

  9. Celery与Django的结合

    一.什么是Celery Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以实现任务的异步处理以及定时任务的处理,它的基本工作流程是: 先启动任务执行单元Worker,让它一 ...

  10. bzoj4489 [Jsoi2015]地铁线路 最短路

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4489 题解 感觉又被骗了.看这道题的 AC 人数不多,以为是一道很好的题目.结果发现是一个非常 ...