Bomb HDU
来源:互联网 发布:软件项目总监职责 编辑:程序博客网 时间:2024/05/17 21:06
There are N bombs needing exploding.
Each bomb has three attributes: exploding radius riri, position (xi,yi)(xi,yi) and lighting-cost cici which means you need to pay cici cost making it explode.
If a un-lighting bomb is in or on the border the exploding area of another exploding one, the un-lighting bomb also will explode.
Now you know the attributes of all bombs, please use the minimum cost to explode all bombs.
Input
First line contains an integer T, which indicates the number of test cases.
Every test case begins with an integers N, which indicates the numbers of bombs.
In the following N lines, the ith line contains four intergers xi, yi, ri and cici, indicating the coordinate of ith bomb is (xi,yi), exploding radius is ri and lighting-cost is cici.
Limits
Output
For every test case, you should output ‘Case #x: y’, where x indicates the case number and counts from 1 and y is the minimum cost.
Sample Input
1
5
0 0 1 5
1 1 1 6
0 1 1 7
3 0 2 10
5 0 1 4
Sample Output
Case #1: 15
粗略看一下还以为是dp,慢慢反应过来有点图论的意思,先一个点引爆如何在范围内都可以引爆,相当于有了一个有向箭头,指向了各个被引爆的点,但是反之不亦然,所有就是一个有向图,假设建完图了,其实发现就是求连通分量即可,取这个连通分量的最小花费的点就好,显然就是tarjan算法然后缩点,最后把所有只要是出度为0的点的花费加起来即可,tarjan的固定模式,算是简单题
#include<cstdio>#include<iostream>#include<queue>#include<cstring>#include<vector>#include<algorithm>#include<cmath>#include<map>#include<stack>#define N 1005#define INF 1000000;using namespace std;int n;int x[N],y[N],r[N],c[N];vector<int>graph[N];long long dis(int p1,int p2){ return (long long)(x[p1]-x[p2])*(x[p1]-x[p2])+(long long)(y[p1]-y[p2])*(y[p1]-y[p2]);}stack<int> st;bool inS[N];int DFN[N],low[N];int belong[N];int val[N];int countt,index1;int inD[N];tarjan(int x){ DFN[x]=low[x]=index1++; inS[x]=true; st.push(x); for(int i=0;i<graph[x].size();i++) { int v=graph[x][i]; if(!DFN[v]) { tarjan(v); low[x]=min(low[x],low[v]); } else if(inS[v]) low[x]=min(low[x],DFN[v]); } if(low[x]==DFN[x]) { val[countt]=INF; while(st.top()!=x) { int v=st.top(); st.pop(); inS[v]=false; belong[v]=countt; val[countt]=min(val[countt],c[v]);//去最小的花费作为缩点以后的权值 } int v=st.top(); st.pop(); inS[v]=false; belong[v]=countt; val[countt]=min(val[countt],c[v]); countt++; }}int work(){ for(int i=1;i<=n;i++) for(int j=0;j<graph[i].size();j++) { int v=graph[i][j]; if(belong[v]!=belong[i]) inD[belong[v]]++; } int ans=0; for(int i=0;i<countt;i++) if(!inD[i]) ans+=val[i]; return ans;}void init(){ for(int i=1;i<=n;i++) graph[i].clear(); index1=1; countt=0; memset(inD,0,sizeof(inD)); memset(DFN,0,sizeof(DFN));}int main(){ int t; scanf("%d",&t); int ca=1; while(t--) { scanf("%d",&n); init(); for(int i=1;i<=n;i++) { scanf("%d%d%d%d",x+i,y+i,r+i,c+i); for(int j=1;j<i;j++) { long long d=dis(i,j); if((long long)r[j]*r[j]>=d) graph[j].push_back(i); if((long long)r[i]*r[i]>=d) graph[i].push_back(j); }//直接n方建图 } for(int i=1;i<=n;i++) if(!DFN[i]) tarjan(i); printf("Case #%d: %d\n",ca++,work()); } return 0;}
- Bomb HDU
- Bomb HDU
- hdu HDU 3555 Bomb
- hdu 2873 Bomb Game
- hdu 2873 Bomb Game
- hdu 3555 Bomb
- hdu 3622 bomb game
- hdu 3622 Bomb Game
- hdu 3555 Bomb
- HDU 3555 Bomb
- hdu 3555 Bomb
- hdu 3622 Bomb Game
- HDU:3555 Bomb
- HDU 3555 Bomb
- hdu 3555 Bomb
- hdu 3555 Bomb
- hdu 3555 Bomb
- hdu 3555 Bomb
- 统计学简介之八——一个总体参数的区间估计
- 分布式与集群的区别
- 序列(rms模拟7-1)* *(贪心)
- VS2010 MFC Dialog设置定时器
- 微信打开本地app
- Bomb HDU
- codeforces 847M Weather Tomorrow
- 商城HTML整站模版
- mysql报错Access denied for user 'ODBC'@'localhost' (using password: N O)解决
- 第十六届住博会毕加索智能科技有限公司承办BIM技术与建筑会议
- 面向对象编程
- bazel
- 从尾到头打印链表
- 第三周-项目四(1)顺序表应用