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 ...
随机推荐
- php页面出现空白解决方法
查询php程序使用内存情况 $size = memory_get_usage(); file_put_contents("d:/data.php", var_export($siz ...
- CodeChef Mahesh and his lost array
Mahesh and his lost array Problem code: ANUMLA Submit All Submissions All submissions for this ...
- 复制书稿 (dp+贪心)
[题目描述] 现在要把m本有顺序的书分给k个人复制(抄写),每一个人的抄写速度都一样,一本书不允许给两个(或以上)的人抄写,分给每一个人的书,必须是连续的,比如不能把第一.第三和第四本书给同一个人抄写 ...
- hdu 6301 Distinct Values (思维+set)
hdu 6301 Distinct Values 题目传送门 题意: 给你m个区间,让你求出一个长度为n的区间且满足在这些区间的数不重复, 并且要求字典序最小 思路: 如果我们已经求出这个序列了,你会 ...
- 数组Array的方法调用
<script language="JavaScript" type="text/javascript"> var arr = ["11& ...
- React(3) --react绑定属性
react绑定属性 /* react绑定属性注意: class要换成className for要换成 htmlFor style: <div style={{"color": ...
- 微信小程序(6)--获取屏幕宽度及弹窗滚动与页面滚动冲突
1.获取屏幕宽度,并赋值给view <view class="ships-img" style="height:{{windowWidth}}px;"&g ...
- 脚本_根据 md5 校验码,检测文件是否被修改
#!bin/bash#功能:根据 md5 校验码,检测文件是否被修改#作者:liusingbon#本示例脚本检测的是/etc 目录下所有的 conf 结尾的文件,根据实际情况,您可以修改为其他目录或文 ...
- MAT in eclipse - memory analyzer
In Help > Install New Software..., enter the following update site URL: http://download.eclipse.o ...
- OtterCTF - Reverse - Msg Me This
原文地址:Msg Me This 题目 Category: Reverse Engineering Points: 500 Solves: 15 Description: Rick created a ...