tjut 5934
来源:互联网 发布:安卓程序员待遇 编辑:程序博客网 时间:2024/06/04 23:19
#include <bits/stdc++.h>using namespace std;typedef __int64 LL;typedef pair<LL, LL> PLL;const int MAXN = 1000 + 5;int T, cas, N;struct QNode { LL x, y, r, c, id;} q[MAXN];vector<int> G[MAXN];int In[MAXN]; // 入度int Low[MAXN], DFN[MAXN], Stack[MAXN], Belong[MAXN]; //Belong数组的值是1~sccint Index, top;int scc;//强连通分量的个数bool Instack[MAXN];int num[MAXN];//各个强连通分量包含点的个数,数组编号1~sccLL w[MAXN]; // 联通分量中最小值void Tarjan(int u) { int v, sz = G[u].size(); Low[u] = DFN[u] = ++Index; Stack[top++] = u; Instack[u] = true; for(int i = 0; i < sz; i++) { v = G[u][i]; if(!DFN[v]) { Tarjan(v); if( Low[u] > Low[v] )Low[u] = Low[v]; } else if(Instack[v] && Low[u] > DFN[v]) Low[u] = DFN[v]; } if(Low[u] == DFN[u]) { scc++; do { v = Stack[--top]; Instack[v] = false; Belong[v] = scc; num[scc]++; } while( v != u); }}void work() { memset(DFN, 0, sizeof(DFN)); memset(Instack, false, sizeof(Instack)); memset(num, 0, sizeof(num)); memset(In, 0, sizeof(In)); Index = scc = top = 0; for(int i = 1; i <= N; i++) if(!DFN[i]) Tarjan(i); memset(w, 0x3f, sizeof(w)); for(int u = 1; u <= N; u++) { int x = Belong[u], y, v, sz = G[u].size();; w[x] = min(w[x], q[u].c); for(int j = 0; j < sz; j++) { v = G[u][j], y = Belong[v]; if(x == y) continue; In[y] ++; } }}inline bool IsInter(QNode& a, QNode& b) { LL dist = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); return dist <= a.r * a.r;}int main() { scanf("%d", &T); cas = 0; while(T --) { scanf("%d", &N); for(int i = 1; i <= N; i++) { scanf("%I64d %I64d %I64d %I64d", &q[i].x, &q[i].y, &q[i].r, &q[i].c); } for(int i = 1; i <= N; i++) { G[i].clear(); for(int j = 1; j <= N; j++) { if (j == i) continue; if(IsInter(q[i], q[j])) { G[i].push_back(j); } } } work(); LL ans = 0; for(int i = 1; i <= scc; i++) { if(In[i] == 0) { ans += w[i]; } } printf("Case #%d: %I64d\n", ++cas, ans); } return 0;}
0 0
- tjut 5934
- tjut 5289
- tjut 5288
- tjut 5294
- tjut 2586
- tjut 5296
- tjut 5297
- tjut 5299
- tjut 5384
- tjut 5387
- tjut 5386
- tjut 5381
- tjut 5400
- tjut 5399
- tjut 5396
- tjut 5398
- tjut 5412
- tjut 5410
- C#利用MySQL的BLOB存储和读取文件和对象
- 模板
- vue的问题
- JavaScript找到一个元素的父节点
- MySQL5.6设置Win下设置大小写敏感
- tjut 5934
- 我不是四色定理
- Spring定时器
- Android5.1-s5p6818平台去掉MMA8653模块驱动、HDMI驱动、TVOUT驱动
- stm32 KEIL软件设置程序烧写起始地址
- LeetCode Arranging Coins
- 花花的森林
- Python Coding Tricks
- LED灯循环闪灭