In Action(最短路+01背包)
In Action
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4764 Accepted Submission(s): 1569

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.
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.
If not exist print "impossible"(without quotes).
2 3
0 2 9
2 1 3
1 0 2
1
3
2 1
2 1 3
1
3
- #include<cstdio>
- #include<iostream>
- #include<cstring>
- #include<cmath>
- #include<algorithm>
- using namespace std;
- #define mem(x,y) memset(x,y,sizeof(x))
- const int INF=0x3f3f3f3f;
- const int MAXN=;
- const int MAXM=<<;
- struct Node{
- int u,v,w;
- };
- Node dt[MAXM];
- int edgnum,n;
- int dis[MAXN];
- int bag[];
- int power[MAXN];
- int add(int u,int v,int w){
- dt[edgnum].u=u;dt[edgnum].v=v;dt[edgnum++].w=w;
- }
- void Bellman(){
- mem(dis,INF);dis[]=;
- for(int j=;j<=n;j++){
- for(int i=;i<edgnum;i++){
- int u=dt[i].u,v=dt[i].v,w=dt[i].w;
- dis[v]=min(dis[v],dis[u]+w);
- }
- }
- }
- int main(){
- int m,T;
- scanf("%d",&T);
- while(T--){
- edgnum=;
- scanf("%d%d",&n,&m);
- int u,v,w;
- while(m--){
- scanf("%d%d%d",&u,&v,&w);
- add(u,v,w);add(v,u,w);
- }
- mem(bag,);
- int V=,sum=;
- for(int i=;i<=n;i++)scanf("%d",power+i),V+=power[i];
- int flot=;
- Bellman();
- for(int i=;i<=n;i++){
- if(dis[i]==INF){
- continue;
- }
- sum+=dis[i];
- }
- for(int i=;i<=n;i++){
- if(dis[i]!=INF)
- for(int j=sum;j>=dis[i];j--){
- bag[j]=max(bag[j],bag[j-dis[i]]+power[i]);
- }
- }
- int i;
- for(i=;i<sum;i++)if(bag[i]>V/){//不能是(v+1)/2。。。
- flot=;
- break;
- }
- if(flot)printf("%d\n",i);
- else puts("impossible");
- }
- return ;
- }
In Action(最短路+01背包)的更多相关文章
- HDU 3339 In Action 最短路+01背包
题目链接: 题目 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu3339In Action(最短路+01背包)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, whe ...
- HDU 3339 In Action【最短路+01背包】
题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Other ...
- HDU 3339 In Action【最短路+01背包模板/主要是建模看谁是容量、价值】
Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the n ...
- HDU-3339 IN ACTION(Dijkstra +01背包)
Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the ...
- *HDU3339 最短路+01背包
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 3339 最短路+01背包
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdoj--3339--In Action(最短路+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 3339 In Action (最短路径+01背包)
In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- oracle中 some、any、all 三者的区别及个人总结,归纳!
any :如果是大于号时( a > b ),那么a中所有大于b中最小的那个数的值,就会被输出出来. 如果是小于号时( a < b ),那么a中所有小于b中最大的那个数的值,就会被输出出来. ...
- 转 --maven系列之一 简介
http://blog.csdn.net/jiuqiyuliang/article/details/41076215 [项目管理和构建]——Maven简介(一) 2015-01-31 21:27 68 ...
- linux php文件include失败 一个很神奇的问题
1. html生成失败,权限问题 前天用php生成模板,在windows上开发,include文件,读缓存写文件,顺风顺水,晚上写完后传到linux上html生成失败,发现文件和文件夹都没生成,网上查 ...
- linux杂记(十)what is BASH Shell
first,what is shell?其实只要是碰过计算机的,对于OS(Operation System操作系统,不管是linux.unix.windows)有点概念的人大多都听过这个名词,因为只要 ...
- CSS3 Media Query
在移动端火爆的今日,一个好的web应用不仅仅要有对应移动平台的APP,自己web网页也需要对不同屏幕大小的移动设备进行支持,也就是我们所说的响应式web页面. 本篇文章就来介绍下最常见的响应式页面的实 ...
- Redhat Linux内核升级全记录(转)
http://www.sina.com.cn 2001/06/15 15:38 中国电脑教育报 李红 Redhat Linux因为比较容易上手,所以用户很多.它系统配置完善,预装了丰富的应 ...
- 6_StopWatch
6 // // ViewController.swift // StopWatch // // Created by ZC on 16/1/9. // Copyright © 2016年 ZC. Al ...
- System timers granularity
http://code.google.com/p/javasimon/wiki/SystemTimersGranularity
- 谷歌日志库GLog 使用说明
1 引用头文件 加载库 #include <glog/include/logging.h> #pragma comment(lib,"libglog.lib") 2 初 ...
- HDU 4981 Goffi and Median
题解:排序取中位数,然后与平均数比较即可. #include <cstdio> #include <algorithm> using namespace std; double ...