题目链接:【http://acm.hdu.edu.cn/showproblem.php?pid=3339】

In Action

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5951    Accepted Submission(s): 1998

Problem Description
Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the number of nuclear weapons have soared across the globe.
Nowadays,the crazy boy in FZU named AekdyCoin possesses some nuclear weapons and wanna destroy our world. Fortunately, our mysterious spy-net has gotten his plan. Now, we need to stop it.
But the arduous task is obviously not easy. First of all, we know that the operating system of the nuclear weapon consists of some connected electric stations, which forms a huge and complex electric network. Every electric station has its power value. To start the nuclear weapon, it must cost half of the electric network's power. So first of all, we need to make more than half of the power diasbled. Our tanks are ready for our action in the base(ID is 0), and we must drive them on the road. As for a electric station, we control them if and only if our tanks stop there. 1 unit distance costs 1 unit oil. And we have enough tanks to use.
Now our commander wants to know the minimal oil cost in this action.
 
Input
The first line of the input contains a single integer T, specifying the number of testcase in the file.
For each case, first line is the integer n(1<= n<= 100), m(1<= m<= 10000), specifying the number of the stations(the IDs are 1,2,3...n), and the number of the roads between the station(bi-direction).
Then m lines follow, each line is interger st(0<= st<= n), ed(0<= ed<= n), dis(0<= dis<= 100), specifying the start point, end point, and the distance between.
Then n lines follow, each line is a interger pow(1<= pow<= 100), specifying the electric station's power by ID order.
 
Output
The minimal oil cost in this action.
If not exist print "impossible"(without quotes).
 
Sample Input
2
2 3
0 2 9
2 1 3
1 0 2
1
3
2 1
2 1 3
1
3
 
Sample Output
5
impossible
 
Author
Lost@HDU
 
Source
 
Recommend
lcy
题意:给出N个供电站编号从1~N,然后给出M条边:基地(编号为0)到某些供电站之间的距离和供电站之间的距离,并且给出这N个供电站的电量。每辆坦克从基地出发去攻击供电站,并且每辆坦克只能攻击一个供电站,求要使的破坏总电量的一半以,求这些坦克要走的最短距离。
题解:最短路+01背包。
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e7 + ;
const int maxn = ;
int N, M;
int mp[][], val[];
int dis[], inq[];
void SPFA(int st)
{
for(int i = ; i <= N; i++)
dis[i] = INF, inq[i] = ;
dis[st] = ;
queue<int> que;
que.push(st);
inq[st] = ;
while(!que.empty())
{
int u = que.front();
inq[u] = ;
que.pop();
for(int v = ; v <= N; v++)
{
if(v == u) continue;
if(dis[v] > dis[u] + mp[u][v])
{
dis[v] = dis[u] + mp[u][v];
if(!inq[v]) que.push(v), inq[v] = ;
}
}
}
}
int main ()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d", &N, &M);
for(int i = ; i <= N; i++)
{
for(int j = ; j <= N; j++)
mp[i][j] = INF;
mp[i][i] = ;
}
int u, v, len;
for(int i = ; i <= M; i++)
{
scanf("%d%d%d", &u, &v, &len);
if(mp[u][v] > len) mp[u][v] = mp[v][u] = len;
}
SPFA();
int sum = ;
for(int i = ; i <= N; i++)
scanf("%d", &val[i]), sum += val[i];
int dp[sum + ];
for(int i = ; i <= sum; i++)
dp[i] = INF;
dp[] = ;
for(int i = ; i <= N; i++)
for(int j = sum; j >= val[i]; j--)
dp[j] = min(dp[j], dp[j - val[i]] + dis[i]);
int ans = INF;
for(int i = sum / + ; i <= sum; i++)
ans = min(ans, dp[i]);
if(ans == INF)
printf("impossible\n");
else
printf("%d\n", ans);
}
return ;
}

最新文章

  1. Android Studio :enable vt-x in your bios security,已经打开还是报错的解决方法
  2. ACM/ICPC 之 BFS范例(ZOJ2913-ZOJ1136(POJ1465))
  3. 利用GCC编译器生成动态链接库和静态链接库
  4. Java集合---Arrays类源码解析
  5. LinQ系列文章
  6. java中DriverManager跟DataSource获取getConnection有什么不同?
  7. 浅谈Ddos攻击攻击与防御
  8. Unieap3.5-禁用Form表单中的全部标签
  9. iOS 5.0 后UIViewController新增:willMoveToParentViewController和didMoveToParentViewCon
  10. [转]linux 如何改变文件属性与权限
  11. Standford CoreNLP
  12. [OFBiz]开发 四
  13. singleTask TaskAffinity allowTaskReparenting
  14. 用js制作日期 2017-03-23
  15. 菜鸟学python之大数据的初认识
  16. (Python3) 求中位数 代码
  17. javascript 数据类型 -- 检测
  18. Linux动态库生成与使用指南
  19. 日志监控文件中获取ip,每一分钟统计一次,超过200次的计入黑名单
  20. Confluence 6 重构索引缓慢

热门文章

  1. 【BZOJ】1176: [Balkan2007]Mokia
  2. 20155117 王震宇 2006-2007-2 《Java程序设计》第三周学习总结
  3. 浅谈Stein算法求最大公约数(GCD)的原理及简单应用
  4. Windows Live Writer博客草稿迁移的一种解决方案
  5. Lithium中关键特性更新
  6. python模块分析之sqlite3数据库
  7. Linux系统中提示/usr/bin/ld: cannot find -lxxx错误的通用解决方法
  8. 一个设置为display:none;的div,在用.height()方法获取不到它的高,获取到的高度为0.
  9. bind1st bind2nd的使用
  10. HDU 2053 Switch Game(开灯问题,完全平方数)