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. Tensorflow机器学习入门——MINIST数据集识别

    参考网站:http://www.tensorfly.cn/tfdoc/tutorials/mnist_beginners.html #自动下载并加载数据 from tensorflow.example ...

  2. python学习第三十二天函数的闭包

    python函数中嵌套另外一个函数,另外一个函数形成一个封闭的环境,里面的那个函数叫做函数的闭包,函数的闭包好处可以保护函数里面的变量,下面讲述函数闭包的实例和用法 1,函数闭包的实例 a='cat' ...

  3. 关于在IE下JavaScript的 Stack overflow at line 错误可能的原因

    该错误只在IE中出现,出现该提示的原因主要有两种: 1. 重定义了系统的触发事件名称作为自定义函数名如:  onclick / onsubmit …  都是系统保留的事件名称,不允许作为重定义函数名称 ...

  4. 2018-11-3-git-分支改名

    title author date CreateTime categories git 分支改名 lindexi 2018-11-3 12:49:9 +0800 2018-2-13 17:23:3 + ...

  5. 02.Linux-CentOS系统NFS挂载时拒绝访问挂载问题

    问题: 在挂载nfs时报拒绝访问挂载:mount -t nfs 192.163.1.10:/home/opneuser/upload /home/openuser/upload/ 报错信息:Mount ...

  6. bootz to be continued

    dmesgcat /proc/interrupts cat /proc/meminfocat /proc/cpuinfo top bootz 0x10000000 0x12000000 0x11000 ...

  7. web项目使用fastdsf上传|下载文件

    在上传代码中添加一下代码 suffix=suffix.substring(1); fast.FastDFSFile file = new fast.FastDFSFile(mFile.getBytes ...

  8. phpstorm ftp不能连接服务器

    环境: ubuntu phpstorm 问题一. 服务器ftp功能没有开启 解决方法:在服务器上安装 ftp 服务 https://i.cnblogs.com/EditPosts.aspx?posti ...

  9. maven仓库mirrors

    <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> & ...

  10. kill命令的几种信号

    1 HUP: hangup 2 INIT: 相当于 Ctrl + c 9 KILL 15 TERM: Terminate (kill 的默认信号) 18 CONT: Continue (从STOP信号 ...