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

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

  1. PAT 2019 春

    算是第二次做这套题吧,感觉从上次考试到现在自己有了挺大提高,提前30min做完了. 7-1 Sexy Primes 读懂题意就行. #include <cstdio> #include & ...

  2. PAT 2019 秋

    考试的还行.不过略微有点遗憾,但是没想到第一题会直接上排序和dfs,感觉这次的题目难度好像是倒着的一样.哈哈哈哈. 第一题实在是搞崩心态,这道题给我的感觉是,可以做,但事实上总是差点啥. 第二题,第三 ...

  3. PAT(甲级)2019年春季考试

    7-1 Sexy Primes 判断素数 一个点没过17/20分 错因:输出i-6写成了输出i,当时写的很乱,可以参考其他人的写法 #include<bits/stdc++.h> usin ...

  4. 三月pat(转)

    转自https://blog.csdn.net/weixin_40688413/article/details/88082779 担心别人删除了就找不到了.因为九月要考. 7-1 Sexy Prime ...

  5. 2019秋季PAT甲级_C++题解

    2019 秋季 PAT (Advanced Level) C++题解 考试拿到了满分但受考场状态和知识水平所限可能方法不够简洁,此处保留记录,仍需多加学习.备考总结(笔记目录)在这里 7-1 Fore ...

  6. 2019秋季PAT甲级_备考总结

    2019 秋季 PAT 甲级 备考总结 在 2019/9/8 的 PAT 甲级考试中拿到了满分,考试题目的C++题解记录在这里,此处对备考过程和考试情况做一个总结.如果我的方法能帮助到碰巧点进来的有缘 ...

  7. [ICCV 2019] Weakly Supervised Object Detection With Segmentation Collaboration

    新在ICCV上发的弱监督物体检测文章,偷偷高兴一下,贴出我的poster,最近有点忙,话不多说,欢迎交流- https://arxiv.org/pdf/1904.00551.pdf http://op ...

  8. PAT甲级【2019年3月考题】——A1158 TelefraudDetection【25】

    Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting ...

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

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

随机推荐

  1. Linux固定ip配置

    第一步:查看网络信息 [root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu ...

  2. python学习第十一天列表的分片和运算

    列表的分片也叫切片,也就是从列表中取出一段赋值给另外一个变量,列表运算就是可以进行比较运算,连接运算,乘法运算等. 1,列表的分片 n1=[1,2,3,4,5,6,7,8,9] n2=[1:3] 包含 ...

  3. dataTable获取所有数据

    "drawCallback": function(settings,e) { var api = new $.fn.dataTable.Api( settings ); resul ...

  4. ASE Alpha Sprint - backend scrum 6

    本次scrum于2019.11.11在sky garden进行,持续30分钟. 参与人: Zhikai Chen, Jia Ning, Hao Wang 请假: Xin Kang, Lihao Ran ...

  5. worldcloud库的使用

    worldcloud库的使用 worldcloud是一个优秀的第三方词云展示库,用来实现比较有逼格的数据可视化效果.更加直观与艺术的展示单词. worldcloud对象的创建 worldcloud.W ...

  6. how to pass variable from shell script to sqlplus

    script sqlplus ${ORA_USR}/${ORA_PASS}@${ORA_DB} @${PARM}/TEST $new_usr $model_usr $new_pwd parm of s ...

  7. 1.VUE前端框架学习记录一

    VUE前端框架学习记录一文字信息没办法描述清楚,主要看编码实战里面,有附带有一个完整可用的Html页面,有需要的同学到脑图里面自取.脑图地址http://naotu.baidu.com/file/f0 ...

  8. 【Leetcode周赛】从contest-111开始。(一般是10个contest写一篇文章)

    Contest 111 (题号941-944)(2019年1月19日,补充题解,主要是943题) 链接:https://leetcode.com/contest/weekly-contest-111 ...

  9. springboot dubbo logback shutdownhook简单总结

      public class Test { public static void main(String[] args){ System.out.println("1: Main start ...

  10. Linux centos7安装git

    1.下载git wget https://github.com/git/git/archive/v2.14.1.zip 2.安装依赖 yum -y install zlib-devel openssl ...