In Action

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

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
 
题解:01背包+最短路;
代码:
 #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背包)的更多相关文章

  1. HDU 3339 In Action 最短路+01背包

    题目链接: 题目 In Action Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  2. hdu3339In Action(最短路+01背包)

    http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, whe ...

  3. HDU 3339 In Action【最短路+01背包】

    题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=3339] In Action Time Limit: 2000/1000 MS (Java/Other ...

  4. HDU 3339 In Action【最短路+01背包模板/主要是建模看谁是容量、价值】

     Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the n ...

  5. HDU-3339 IN ACTION(Dijkstra +01背包)

      Since 1945, when the first nuclear bomb was exploded by the Manhattan Project team in the US, the ...

  6. *HDU3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  7. HDU 3339 最短路+01背包

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  8. hdoj--3339--In Action(最短路+01背包)

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. hdu 3339 In Action (最短路径+01背包)

    In Action Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 用原生JS写移动动画案例及实际应用

    js很强大 相信很多人都知道,那么它有哪些强大之处呢?有兴趣的人可以去查查,这里就不赘述了,因为不在本片文章讨论的范围. 我们要讲的是怎么用原生JS写移动动画?我们先举一个最简单的动画例子,很多网站的 ...

  2. python打包成exe

    目前有三种方法可以实现python打包成exe,分别为 py2exe Pyinstaller cx_Freeze 其中没有一个是完美的 1.py2exe的话不支持egg类型的python库 2.Pyi ...

  3. BZOJ 4311: 向量( 按时间分治 + 线段树 )

    离线, 然后按时间分治, 每个向量都有出现时间[l, r], 直接插入时间线段树(一个向量只会影响O(logN)数量级的线段树节点). 在线段树每个节点弄出凸壳然后二分. 时间复杂度O(Nlog^2N ...

  4. 理解ROS的参数

    记住每次操作之前都要在一个单独的终端中运行ros的核心. roscore rosparam命令允许你在ROS的参数服务器上操作和存储数据,参数服务器可以存储整数,浮点数,布尔类型,字典,列表.ROS使 ...

  5. mssql字符串分割后的值,把表中不存在的插入表中

    字符串分割后的值,把表中不存在的插入表中 --供大家参考 使用场景,自行思考…… --创建表tb1 Create table tb1 ( cola int, colb ) ) --插入数据 inser ...

  6. 移动前端制作篇之javascript篇

    javascript(简称js)语言在移动前端应用很广.可以说必不可少,许多效果都是和js相关的.包括现在移动端的一些框架.jqmobi.jqtouch.sencha touch.jquerymobi ...

  7. 关于GitHub账号及文章选题

    课程:软件测试基础 姓名:胡东妮 学号:2014218028 github账号:hudongni1 文章选题:测试用例的自动生成  邮箱:dongnihu@tju.edu.cn

  8. CCNP路由实验(3) -- 路由控制

    1.用distribute-list过滤路由在不同协议里的用法 在RIP里 在EIGRP里 在OSPF里 只接收奇数路由 只接收偶数路由 只接收被4整除的路由2.offset-list在不同协议里的用 ...

  9. 脑波设备mindwave数据流二次开发示例

    数据流开发神念科技提供了两个文件ThinkGearStreamParse.h和ThinkGearStreamParse.cpp两个文件,主要接口为: 宏定义: /* Data CODE definit ...

  10. c#打印记忆功能

    下面这些实例都可以拷下直接用 总体思路:保存打印设置信息到本地文件,下次打印的时候直接读取文件信息,通过序列化与反序列化来获取值.本例只是针对打印的横纵向进行设置,读者也可以增加其他设置信息进行保存读 ...