7-3 Telefraud Detection 未作答 得分: 0 / 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 KKK 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. AAA makes a short phone call to BBB means that the total duration of the calls from AAA to BBB 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 KKK (≤500\le 500≤500, the threshold(阈值) of the amount of short phone calls), NNN (≤103\le 10^3≤103, the number of different phone numbers), and MMM (≤105\le 10^5≤105, the number of phone call records). Then MMM lines of one day's records are given, each in the format:
caller receiver duration
where caller
and receiver
are numbered from 1 to NNN, 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
思路分析
参照了大佬代码
1、建图+初始化权值(总通话时间)
2、全图遍历邻接矩阵,寻找Crime(阈值k、短电话5min、20%回电)
Crime默认排好是从小到大的
3、如果Crime为空,输出None
如果Crime不为空,从小到大(首到尾)依次找当前元素的同伙,找到入队,之后队内元素再找同伙,直到找到所有同伙,期间用标志位辅助,同伙全部入gang,最后对gang进行排序
ps:此题比较麻烦的是要找许多条件来判断是不是Crime与是不是gang
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#define MAX 1010
using namespace std;
int adt[MAX][MAX];
bool vis[MAX];
int main()
{
int k,n,m,a,b,t;
cin>>k>>n>>m;
for(int i=0;i<m;i++)//init
{
cin>>a>>b>>t;
adt[a][b]+=t;
}
vector<int>v;
for(int i=1;i<=n;i++)//find crime
{
int cnt=0,back=0;
for(int j=1;j<=n;j++)
{
if(adt[i][j]!=0&&adt[i][j]<=5)
{
cnt++;
if(adt[j][i]!=0)back++;
}
}
double per=back*1.0/cnt;
if(cnt>k&&per<=0.2)v.push_back(i);
}
for(int i=0;i<v.size();i++)
{
int cur=v[i];
if(!vis[cur])
{
cout<<cur;
vis[cur]=true;
queue<int>other;
vector<int>gang;
for(int j=i+1;j<v.size();j++)
{
int tmp=v[j];
if(vis[tmp]==false&&adt[cur][tmp]!=0&&adt[tmp][cur]!=0)
{
vis[tmp]=true;
other.push(tmp);
gang.push_back(tmp);
}
}
while(other.empty()==false)
{
int first=other.front();
other.pop();
for(int j=0;j<v.size();j++)
{
int tmp=v[j];
if(vis[tmp]==false&&adt[cur][tmp]!=0&&adt[tmp][cur]!=0)
{
vis[tmp]=true;
other.push(tmp);
gang.push_back(tmp);
}
}
}
sort(gang.begin(),gang.end());
for(int j=0;j<gang.size();j++)
printf(" %d",gang[j]);
cout<<endl;
}
}
if(v.size()==0)cout<<"None";
}