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
callerandreceiverare numbered from 1 to N, anddurationis 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
Noneinstead.
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
1had 9 records, but there were 7 distinct receivers, among which5and15both had conversations lasted more than 5 minutes in total. Hence1had 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 ...
随机推荐
- mysql 主从复制(mysql双机热备的实现)
转:http://blog.csdn.net/qq394829044/article/details/53203645 Mysql数据库没有增量备份的机制,当数据量太大的时候备份是一个很大的问题.还好 ...
- LOJ 2234/BZOJ 3629 聪明的燕姿(数论+DFS)
题面 传送门 分析 看到约数之和,我们首先想到约数和公式 若$ x=\prod_{i=1}^{n}p_i^{k_i} \(,则x的约数和为\) \prod_{i=1}^{n} \sum_{j=0}^{ ...
- II play with GG
https://ac.nowcoder.com/acm/contest/338/I 题解:首先轮到出手的时候如果在(0,0)上肯定是输的,而(0,1)(1,0)(0,2)(2,0)(1,1)肯定是赢的 ...
- jquery实现全选,反选,取消的操作
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#设计模式:适配器模式(Adapter Pattern)
一,Adapter适配器模式是将两个不兼容的类组合在一起使用,如下例子 using System; using System.Collections.Generic; using System.Lin ...
- windos忘记密码登陆如何修复
一.简单的方法: 开机启动windows,进入欢迎界面后,会出现输入用户名密码提示框,这时候,同时按住Ctrl+Alt+Delete,会跳出一个账号窗口,输入用户名:administer,按回车即可. ...
- Mata标签,og标签
一.Mata标签 meta是用来在HTML文档中模拟HTTP协议的响应头报文,meta 标签用于网页的<head>与</head>中.meta 的属性有两种:name和http ...
- opencv保存图片路径包含中文乱码解决方案
# coding: utf-8 import numpy as np import cv2 img = cv2.imread('1.jpg',1) cv2.imshow('image', img) k ...
- 解决嵌套在ScrollView中的TableView滑动手势冲突问题
最近在迭代开发公司项目的时候遇到了一个问题,在可以左右切换标签视图的ScrollView中嵌套了两个TableView用于展示视图,感觉一切so easy的情况下,问题出现了,因为左右两个视图既可以实 ...
- ob_start()、ob_get_contents() 等使用方法
ob_start()ob_get_contents(); 获取缓冲区内容ob_end_clean():删除内部缓冲区的内容,并且关闭内部缓冲区 ob_end_flush() 发送内部缓冲区的内容到浏览 ...