博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 3339 - In Action
阅读量:4991 次
发布时间:2019-06-12

本文共 4349 字,大约阅读时间需要 14 分钟。

先上题目:

In Action

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3352    Accepted Submission(s): 1068

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
3 2
1 2 1
3 1 3
 
 

 

Sample Output
5
impossible
 
  题意:有一堆电站(n个),你有一个基地(0号),每个电站有一点的供电量,给你关于电站和你的基地的无向图,现在需要你控制一部分电站,使得控制的电站的供电量大于总供电量的一半,同时由于控制一个电站需要的一辆坦克,一辆坦克没有一个单位的距离需要一单位的油,问能否可以达到要求,如果可以达到要求,最少需要多少的油。
  这是一题最短路+01背包。首先求出到每一个电站的距离,然后总供电量作为背包的容量,跑一次01背包以后在大于一般供电量的那个供电量开始向总供电量方向扫描找出最小值,这里需要注意的是一定是
大于总供电量的一半。
  这题因为敲的时候因为有一个地方将+=写成=+,结果算上另一个小错误加起来WA了10+次(┬_┬) 。
 
上代码:
 
1 #include 
2 #include
3 #include
4 #define MAX 100005 5 #define LL int 6 #define MAXN 105 7 #define INF 99999999 8 #define max(x,y) (x>y ? x : y) 9 #define min(x,y) (x
q; 47 dis[0]=0; 48 memset(vin,0,sizeof(vin)); 49 for(int i=1;i<=n;i++){ 50 dis[i]=INF; 51 } 52 q.push(0); 53 vin[0]=1; 54 while(!q.empty()){ 55 int u=q.front(); 56 vin[u]=0; 57 q.pop(); 58 for(int v=p[u];v!=-1;v=e[v].next){ 59 //DEBUG(43); 60 int l=dis[u]+e[v].l; 61 if(dis[e[v].to]>l){ 62 dis[e[v].to]=l; 63 if(!vin[e[v].to]){ 64 q.push(e[v].to); 65 vin[e[v].to]=1; 66 } 67 } 68 } 69 //DEBUG(52); 70 } 71 } 72 73 //dij 74 /* 75 bool flag[MAXN]; 76 void dij(int r){ 77 int u; 78 LL minn; 79 memset(flag,0,sizeof(flag)); 80 for(int i=0;i<=n;i++){ 81 dis[i]=INF; 82 } 83 dis[r]=0; 84 for(int i=0;i<=n;i++){ 85 u=-1; 86 minn=INF; 87 for(int j=0;j<=n;j++){ 88 if(!flag[j] && minn>dis[j]){ 89 u=j; 90 minn=dis[j]; 91 } 92 } 93 if(u==-1) return ; 94 flag[u]=1; 95 96 //for(int v=p[u];v!=-1;v=e[v].next){ 97 // dis[e[v].to]=min(dis[e[v].to],dis[u]+e[v].l); 98 // } 99 100 for(int i=0;i<=n;i++){101 if(map[u][i]!=-1){102 dis[i]=min(map[u][i]+dis[u],dis[i]);103 }104 }105 }106 }107 */108 int w[MAXN];109 LL dp[MAX];110 LL minn,wsum;111 112 int main()113 {114 int t;115 int st,ed,l;116 //freopen("data.txt","r",stdin);117 scanf("%d",&t);118 while(t--){119 scanf("%d %d",&n,&m);120 reset();121 for(int i=0;i
l){127 map[st][ed]=l;128 map[ed][st]=l;129 }130 */131 }132 wsum=0;133 for(int i=1;i<=n;i++){134 scanf("%d",&w[i]);135 wsum+=w[i];136 }137 spfa();138 //dij(0);139 for(int i=0;i<=wsum;i++) dp[i]=INF;140 dp[0]=0;141 for(int i=1;i<=n;i++){142 for(int j=wsum;j>=w[i];j--){143 dp[j]=min(dp[j-w[i]]+dis[i],dp[j]);144 //printf("%d ",dp[j]);145 }146 //printf("\n");147 }148 minn=INF;149 for(LL i=(wsum)/2+1;i<=wsum;i++){150 minn=min(dp[i],minn);151 }152 if(minn!=INF) printf("%d\n",minn);153 else printf("impossible\n");154 }155 156 return 0;157 }
3339

 

转载于:https://www.cnblogs.com/sineatos/p/3561529.html

你可能感兴趣的文章
AndroidAutoLayout
查看>>
样本不均衡下的分类损失函数
查看>>
node启动服务后,窗口不能关闭。pm2了解一下
查看>>
vsCode 改变主题
查看>>
【vijos】【树形dp】佳佳的魔法药水
查看>>
聚合新闻头条
查看>>
Ubuntu 关闭锁屏界面的 on-screen keyboard
查看>>
凸优化学习笔记
查看>>
使用ehcache-spring-annotations开启ehcache的注解功能
查看>>
Charles设置HTTPS抓包
查看>>
NGUI出现Shader wants normals, but the mesh UIAtlas doesn&#39;t have them
查看>>
Boost.Asio c++ 网络编程翻译(14)
查看>>
Codeforces Round #306 (Div. 2) D.E. 解题报告
查看>>
uva 1557 - Calendar Game(博弈)
查看>>
HDU1051 Wooden Sticks 【贪婪】
查看>>
十大经典数据挖掘算法
查看>>
Rhythmbox乱码的解决的方法
查看>>
中纪委:抗震中官员临危退缩玩忽职守将被严处
查看>>
MySQL 8.0.12 基于Windows 安装教程
查看>>
在hue中使用hive
查看>>