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. 《剑指offer》面试题9 斐波那契数列 Java版

    书中方法一:递归,这种方法效率不高,因为可能会有很多重复计算. public long calculate(int n){ if(n<=0){ return 0; } if(n == 1){ r ...

  2. Vue对象的生命周期

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. [fw]linux测试工程介绍(Linux Test Project)

    http://ltp.sourceforge.net/ Linux Test Project, 后台很硬,由SGI™ 发起, IBM维护,所以质量有保障. 里面介绍了很多工具,对于一般的基准测试应该是 ...

  4. FY20-ASE 开课!

    自我介绍 我叫陈志锴,undergraduate,pre-phd,初级程序员(c++和c的区别只知道多了类和对象这种,python只会写大作业代码和用基础的neural network框架),曾经跟着 ...

  5. CentOS 6.5之SSH 免密码登录

    0.说明 这里为了方便说明问题,假设有A和B两台安装了centos6.5的主机.目标是实现A.B两台主机分别能够通过ssh免密码登录到对方主机.不同主机的配置过程一样,这里介绍A主机的配置过程. 事先 ...

  6. neuoj Blurred Pictures(小思维题

    https://oj.neu.edu.cn/problem/1505 题意:一张由n*n的照片,每行从第ai个像素点到第bi个像素点是非模糊点,要求找出最大的正方形,该正方形中的像素都是非模糊点. 思 ...

  7. spring boot 提纲

    http://tengj.top/categories/Spring-Boot%E5%B9%B2%E8%B4%A7%E7%B3%BB%E5%88%97/ http://blog.csdn.net/ca ...

  8. Calendar日历

    Calendar calendar=Calendar.getInstance(); //上一年的今天 calendar.add(Calendar.YEAR,-1); System.out.printl ...

  9. 调试web worker (动态生成的worker)

    1.在worker.js源码文件中 写下debugger关键词 2. F12打开控制台,重新刷新页面,加载worker.js文件(注意之前的缓存,chrome推荐使用 ctrl + F5 刷新) 3. ...

  10. Spring Security 安全认证

    Spring Boot 使用 Mybatis 依赖 <dependency> <groupId>org.mybatis.spring.boot</groupId> ...