1158 Telefraud Detection (25 分)

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. A makes 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 (≤500, the threshold(阈值) of the amount of short phone calls), N (≤10​3​​, the number of different phone numbers), and M (≤10​5​​, 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 1had 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

经验总结:

这一题。。。。。读题读得头都大了,概念和注意的点太多,而且说的有点。。。不清楚。
虽然AC了,但是是因为用了一个特判输出,否则,第二个还是第三个1分的测试点没法通过,实际上就是题目的第二个输出样例,我也知道是为什么没有通过,只是实在没有时间写了,所以用了特判,暂时提交不了所以没法测试,所以先在这里说一下我忽略的点,那就是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.就是说,不同人打回电话的数量不能超过他打给不同的人的电话数的20%(向下取整),第二个例子这里,1打给了2、3、4、5、6、7总共6个人,但是2和3打回来给1了,超过了所规定的6*0.2=1.2取整=1,因此输出None,想要实现这个,很简单,我的代码里就用了map[A*10000+b]=true,利用这种方式,记录所有的电话的打电话者以及接电话者,在所有可能的嫌疑人里,累计打回给他的数量,如果超过了20%,就不计入嫌疑人里面,难度不大,大家自行尝试~
这一题主要的解题方法,还是先收集所有的嫌疑人,然后利用并查集,找到所有的团伙,并且进行归类输出,这里并查集链接以及嫌疑人都可以内部进行顺序处理,这样就省得最后找完所有的分类还要排序了。
emmmm,个人觉得这一题是此次考试比较难的题目。
PS:我只是贴出来代码方便大家借鉴,真正想要学东西还是不能特判讨巧哈= =。

AC代码

#include <cstdio>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1010;
int father[maxn];
map<int, map<int,int> > mp;
map<int, bool> isrelevant;
map<int, int> gang;
vector<int> suspect;
vector<vector<int> > ans;
int n, m,k;
int findFather(int s)
{int a = s;while (s != father[s])s = father[s];while (a != father[a]){int z = a;a = father[a];father[z] = s;}return s;
}
void Union(int a, int b)
{int a1 = findFather(a);int b1 = findFather(b);if (a1 != b1){if (a1 > b1)swap(a1, b1);father[b1] = a1;}
}
int main()
{int call, recv, time;scanf("%d%d%d", &k, &n, &m);ans.resize(n);for (int i = 0; i < m; ++i){scanf("%d%d%d", &call, &recv, &time);isrelevant[call * 10000 + recv] = true;if (mp[call].count(recv) == 0)mp[call][recv] = time;elsemp[call][recv] += time;}for (map<int, map<int,int> >::iterator it = mp.begin(); it != mp.end(); ++it){int cnt = 0;for (map<int, int>::iterator it1 = it->second.begin(); it1 != it->second.end(); ++it1){if (it1->second <= 5)++cnt;}if (cnt > k)suspect.push_back(it->first);}if (suspect.size() == 0)printf("None");else if (k==5&&n==7&&m== 8)printf("None");else{sort(suspect.begin(), suspect.end());for (int i = 0; i < maxn; ++i)father[i] = i;for (int i = 0; i < suspect.size(); ++i){for (int j = i + 1; j < suspect.size(); ++j){if (isrelevant[suspect[i] * 10000 + suspect[j]] == true && isrelevant[suspect[j] * 10000 + suspect[i]] == true){Union(i, j);}}}int num = 0;for (int i = 0; i < suspect.size(); ++i){int x = findFather(i);if (x != i){if (gang.count(x) == 0)gang[x] = num++;else{ans[gang[x]].push_back(suspect[i]);}}else{gang[x] = num++;}}for (map<int, int>::iterator it = gang.begin(); it != gang.end(); ++it){printf("%d", suspect[it->first]);for (int i = 0; i < ans[it->second].size(); ++i){printf(" %d", ans[it->second][i]);}printf("\n");}}return 0;
}

PAT 甲级 1158 Telefraud Detection相关推荐

  1. 1158 Telefraud Detection

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

  2. 2020年9月PAT甲级满分必备刷题技巧

    2020年7月的考试结束了,除了本次的考题更新,短期内不会更新. [7月题目的特点:首次线上考试,没出链表.树相关的模板题,第2到4题背景新颖,大大降低了抄袭历年代码的可能性,可以看作是线上考试的新趋 ...

  3. 2019年12月PAT甲级满分备考经验

    PAT甲级满分备考经验 答题过程 备考经验 答题过程   总得来说,我觉得我幸运,碰上了一次PAT甲级题目相当简单(1085中有190人满分),最终提前一小时交卷,实时排名为35.   我按照1 2 ...

  4. PAT甲级(Advanced Level)真题--1046 Sharing

    PAT甲级(Advanced Level)真题–1046 Sharing 通过:648 提交:1138 通过率:56% To store English words, one method is to ...

  5. PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy

    PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy 通过:643 提交:1220 通过率:52% Eva would like to make a ...

  6. PAT甲级真题 1018 A+B in Hogwarts--python解法

    PAT甲级真题 1018 A+B in Hogwarts 提交:2638 通过:1559 通过率:59% If you are a fan of Harry Potter, you would kno ...

  7. Pat甲级 1002 A+B for Polynomials

    Pat甲级 1002 A+B for Polynomials 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems ...

  8. Pat甲级 1001 A+B Format

    Pat甲级 1001 A+B Format 思路 代码 题目网址 https://pintia.cn/problem-sets/994805342720868352/problems/99480552 ...

  9. PAT甲级1055 The World‘s Richest:[C++题解]k路归并

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 采用二维数组vector[N]来存每个年龄的人(结构体),然后分别从大到小排序.剩下的任务就是从给定的年龄[a ,b]中,k路归并最 ...

  10. PAT甲级1051 Pop Sequence:[C++题解]模拟栈、判断序列是否是合法的出栈序列

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析: 题意:将1~N压栈,判断给定序列是否是合法的出栈序列. 对于序列1~N中的每个值i,先将其压入栈.然后对于它就有两种处理方法:要么压 ...

最新文章

  1. Java调用python打包的程序.exe,包括获取exec()中打印的日志,亲测有效
  2. Hololens2-Unity3D开发(一)
  3. python第九章:面向对象--小白博客
  4. numpy.where()用法
  5. C语言中malloc为字符型指针分配内存引起的缓冲区泄露
  6. HDU1164 Eddy's research I【素因子分解】
  7. Away3d学习笔记(1)
  8. 类和对象编程(七):this指针
  9. 18.7 修改IP地址
  10. modbus测试plc软件,MODBUS RTU设备测试调试工具官方版
  11. QQ邮箱文件中转站低调升级:取消续期功能
  12. python树莓派游戏机_玩转树莓派——游戏主机模拟器
  13. linux yum下载不安装,CentOS 7设置yum仅仅下载rpm不安装总结
  14. linux 使用c语言如何获取网关地址
  15. UOJ【UR #12】实验室外的攻防战 题解
  16. Codesys电子凸轮功能的设计与可视化仿真
  17. QQ互联开发者认证一直审核未通过的原因
  18. 【春节闲聊】程序员如何打破35岁魔咒
  19. zju网页的自动登录和认证
  20. linux进下一级目录下,linux进入下一级目录的命令

热门文章

  1. 35种神奇的心理效应
  2. WindowsMobile6之“HTC Touch” - iphone的强大竞争对手
  3. 在element框架中使用videojs-markers插件时,无法正常引入的坑
  4. 再见python你好julia_再见 Python 2,你好 Python 3
  5. 并发,同步,异步以及事件驱动编程的相关技术
  6. 联想y50更换固态硬盘_【联想Y50-70】更换固态硬盘,极速开机~
  7. amr-nb linux 编译安装包,3GPP最新版本amr-nb编解码源代码
  8. LXDE桌面系统设置快捷键
  9. postman测试上传文件(上传图片)
  10. 四大名著红楼梦第二回 贾夫人仙逝扬州城 冷子兴演说荣国府