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,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...
随机推荐
- [已解决]报错: warning: LF will be replaced by CRLF in lib/anime.min.js
git config --global core.autocrlf false
- A AFei Loves Magic
链接:https://ac.nowcoder.com/acm/contest/338/A来源:牛客网 题目描述 AFei is a trainee magician who likes to stud ...
- 攻防世界--simple-unpack
下载链接:https://adworld.xctf.org.cn/media/task/attachments/b7cf4629544f4e759d690100c3f96caa 1.准备 获取到信息: ...
- 浏览器报406 错误:The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers
The resource identified by this request is only capable of generating responses with characteristics ...
- surpace pro 检测维修记录
1.大陆不在全球联保范围内. 2.不要升级系统(win 10 1709)容易键盘失去反应. 3.不要乱安装系统,官方有回复镜像包,记住系列号, 4.大陆没有维修的点,有问题着官方服务, 5.uefi设 ...
- 脚本_备份mysql
#!bin/bash#功能:备份mysql数据 #作者:liusingbon#定义变量 user(数据库用户名),passwd(数据库密码),date(备份的时间标签)#dbname(需要备份的数据库 ...
- springmvc中拦截器配置格式
对于springmvc,有两种方式配置拦截器. 一是实现HandlerInterceptor接口,如 public class MyInterceptor1 implements HandlerInt ...
- java编程实战
线程池为什么要有它: 线程创建要开辟虚拟机栈,释放线程要垃圾回收的. server端要并发访问数据库的. 服务器启动有线程池放着. ----- 线程池的概念: 1.任务队列 2.拒绝策略(抛出异常,直 ...
- SpringBoot JSON文件读取
@Componentpublic class StepExecutor implements Runnable { @Value("classpath:menu.json") pr ...
- vue项目轮播图的实现
利用 Vue-Awesome-Swiper插件来做轮播效果,github地址:https://github.com/surmon-china/vue-awesome-swiper 安装 npm i ...