写在前面
- 思路分析
- 先得到suspects的值,将每个人与他人的电话总时间小于等于5的都存储下来,在去找人数小于等于k的,并且回拨人数不超过他拨出去的20%
- 并查集将suspects进行分类
- 问题点
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.
- 总时长
- 知识半盲点,学习ing
测试用例
-
input: 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 output: 3 5 6 input: 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 output: None
ac代码
- 学习代码
#include <iostream> #include <vector> #include <algorithm> using namespace std; int e[1005][1005], k, n, m, father[1005]; const int inf = 0x7fffffff; int findfather(int x){ int a = x; while(x != father[x]) x = father[x]; while(a != x){ int z = father[a]; father[a] = x; a = z; } return x; } void Union(int a, int b){ int faa = findfather(a), fab = findfather(b); if(faa != fab){ father[fab] = min(faa, fab); father[faa] = min(faa, fab); } } int main(){ scanf("%d %d %d", &k, &n, &m); vector<int>num[n + 1], suspect; fill(e[0], e[0] + 1005 * 1005, inf); for(int i = 0; i < m; ++ i){ int a, b, temp; scanf("%d %d %d", &a, &b, &temp); if(e[a][b] == inf) e[a][b] = 0; e[a][b] += temp; } for(int i = 1; i <= n; ++ i) for(int j = 1; j <= n; ++ j) if(e[i][j] <= 5) num[i].push_back(j); for(int i = 1; i <= n; ++ i){ int len = num[i].size(), cnt = 0; if(len <= k) continue; for(int j = 0; j < num[i].size(); ++ j) if(e[num[i][j]][i] < inf) ++ cnt; if(cnt <= (int) (0.2 * len)) suspect.push_back(i); } if(suspect.size() == 0) printf("None\n"); else{ for(int i = 1; i <= n; ++ i) father[i] = i; for(int i = 0; i < suspect.size(); ++ i) for(int j = i + 1; j < suspect.size(); ++ j) if(e[suspect[i]][suspect[j]] < inf && e[suspect[j]][suspect[i]] < inf) Union(suspect[i], suspect[j]); vector<int>ans[n + 1]; for(int i = 0; i < suspect.size(); ++ i) ans[findfather(suspect[i])].push_back(suspect[i]); for(int i = 1; i <= n; ++ i){ if(ans[i].size() != 0){ sort(ans[i].begin(), ans[i].end()); for(int j = 0; j < ans[i].size(); ++ j){ if(j != 0) printf(" "); printf("%d",ans[i][j]); } printf("\n"); } } } }