PAT 2019-3 7-3 Telefraud Detection
Description:
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. Amakes 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 (≤, the threshold(阈值) of the amount of short phone calls), N (≤, the number of different phone numbers), and M (≤, 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
andreceiver
are numbered from 1 to N, andduration
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 which5
and15
both had conversations lasted more than 5 minutes in total. Hence1
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
Keys:
- 模拟题
Attention:
- A1034的升级版
Code:
/*
嫌疑人:与超过K个不同的人拨打短电话(通话总时长<=5),但是<=20%的人回复电话
犯罪团伙:两个嫌疑人之间互通电话 阈值K<=500,通话人数N<=1e3,通话记录数量M<=1e5
打电话者(1~N),接电话者,通话时长 按行打印犯罪团伙(第一个嫌疑人的序号递增
嫌疑人按照序号递增, 基本思路:
图存储,通话总时长
二重循环遍历图一次,记录每个人往外拨打短电话的人数,并统计其中回复的人数
如果,超过K个人,并且回复的人数re<=0.2*call -> 5*re <= call,认定为嫌疑人
存储至嫌疑人队列 二重循环遍历嫌疑人队列,判断任意两个人是否有过通话
如果有,则Union,并领较小者为父亲结点 再次遍历嫌疑人队列,存储头目,以头目为下标,存储团伙成员 打印,遍历头目,输出团伙成员
*/
#include<cstdio>
#include<vector>
#include<set>
using namespace std;
const int M=1e3+;
int grap[M][M],father[M];
vector<int> gang[M]; int Find(int v)
{
int s=v;
while(v != father[v])
v=father[v];
while(s != father[s])
{
int x = father[s];
father[s] = v;
s = x;
}
return v;
} void Union(int s1, int s2)
{
int f1=Find(s1);
int f2=Find(s2);
if(f1<f2)
father[f2]=f1;
else
father[f1]=f2;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDEG fill(grap[],grap[]+M*M,);
for(int i=; i<M; i++)
father[i]=i; int k,n,m;
scanf("%d%d%d", &k,&n,&m);
for(int i=; i<m; i++)
{
int v1,v2,w;
scanf("%d%d%d", &v1,&v2,&w);
grap[v1][v2] += w;
}
vector<int> suspect;
for(int i=; i<=n; i++)
{
int call=,re=;
for(int j=; j<=n; j++)
{
if(grap[i][j]!= && grap[i][j]<=)
{
call++;
if(grap[j][i]!=)
re++;
}
}
if(call>k && *re<=call)
suspect.push_back(i);
}
for(int i=; i<suspect.size(); i++)
{
for(int j=i+; j<suspect.size(); j++)
{
int s1=suspect[i],s2=suspect[j];
if(grap[s1][s2]!= && grap[s2][s1]!=)
Union(s1,s2);
}
}
set<int> head;
for(int i=; i<suspect.size(); i++)
{
int s = Find(suspect[i]);
head.insert(s);
gang[s].push_back(suspect[i]);
}
if(head.size()==)
printf("None");
else
{
for(auto it=head.begin(); it!=head.end(); it++)
for(int i=; i<gang[*it].size(); i++)
printf("%d%c", gang[*it][i],i==gang[*it].size()-?'\n':' ');
} return ;
}
PAT 2019-3 7-3 Telefraud Detection的更多相关文章
- PAT 2019 春
算是第二次做这套题吧,感觉从上次考试到现在自己有了挺大提高,提前30min做完了. 7-1 Sexy Primes 读懂题意就行. #include <cstdio> #include & ...
- PAT 2019 秋
考试的还行.不过略微有点遗憾,但是没想到第一题会直接上排序和dfs,感觉这次的题目难度好像是倒着的一样.哈哈哈哈. 第一题实在是搞崩心态,这道题给我的感觉是,可以做,但事实上总是差点啥. 第二题,第三 ...
- PAT(甲级)2019年春季考试
7-1 Sexy Primes 判断素数 一个点没过17/20分 错因:输出i-6写成了输出i,当时写的很乱,可以参考其他人的写法 #include<bits/stdc++.h> usin ...
- 三月pat(转)
转自https://blog.csdn.net/weixin_40688413/article/details/88082779 担心别人删除了就找不到了.因为九月要考. 7-1 Sexy Prime ...
- 2019秋季PAT甲级_C++题解
2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...
- 2019秋季PAT甲级_备考总结
2019 秋季 PAT 甲级 备考总结 在 2019/9/8 的 PAT 甲级考试中拿到了满分,考试题目的C++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...
- [ICCV 2019] Weakly Supervised Object Detection With Segmentation Collaboration
新在ICCV上发的弱监督物体检测文章,偷偷高兴一下,贴出我的poster,最近有点忙,话不多说,欢迎交流- https://arxiv.org/pdf/1904.00551.pdf http://op ...
- PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】
Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting ...
- PAT甲级【2019年3月考题】——A1157 Anniversary【25】
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebrat ...
随机推荐
- python安装numpy
命令介绍: D:\computerSoft\python3.6.4\Scripts>python36 pip3.6.exe install numpy # 通过pip下载对应版本的numpy,然 ...
- Python自学第二天学习之《列表》
一. 列表:list类型,是有序的,可以被修改的. 格式 : li=["cd",1,"gfds",[1,2,3]] 1.类型转换: #字符串转换成列表 b=“ ...
- GnuTLS 3.3.3 remote memory corruption(CVE-2014-3466)
Buffer overflow in the read_server_hello function in lib/gnutls_handshake.c in GnuTLS before 3.1.25, ...
- 项目使用Kafka镜像报错处理记录:this server does not host this topic-partition
背景 项目使用docker swarm部署 服务之间使用消息中间件 kafka 通信 Kafka 使用 star 3.7k 的 wurstmeister/kafka:2.12-2.2.1 镜像 Zoo ...
- owaspbwa tickets
owaspbwa tickets 来源 https://sourceforge.net/p/owaspbwa/tickets/ 192 SQL Injection in pic_id paramet ...
- 攻防世界--python-trade
测试文件:https://adworld.xctf.org.cn/media/task/attachments/69c8f29912ae4f679d92a6cd36c33196.pyc 这里需要用到一 ...
- php之ob_start()缓冲区
ob_get_contents()函数及与其相关几个函数的用法 ob_start() ob_get_contents(); 获取缓冲区内容,如果是纯 html内容或标签,则都会放于浏览器的缓冲区中. ...
- 五 shell 变量与字符串操作
特点:1 shell变量没有数据类型的区分 2 Shell 把任何存储在变量中的值,皆视为以字符组成的“字符串”. 3 设定的变量值只在当前shell环境中有作用 4 不能以数字开头 ...
- CF960G Bandit Blues 第一类斯特林数+分治+FFT
题目传送门 https://codeforces.com/contest/960/problem/G 题解 首先整个排列的最大值一定是 \(A\) 个前缀最大值的最后一个,也是 \(B\) 个后缀最大 ...
- BZOJ3625 CF438E 小朋友与二叉树
心态崩了 不放传送门了 辣鸡bz 还是正经一点写一下题解= = 就是显然我们可以把权值写成生成函数形式g(0/1序列)来表示权值是否出现 然后f来表示总的方案数 可以列出 分别枚举左右子树和空树的情况 ...