国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

In Action

2019-11-06 07:24:59
字體:
供稿:網(wǎng)友
In Action

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

題目大意:給定N個電站和M條雙向道路,現(xiàn)在坦克在0號電站,要去炸毀這些電站,問在路徑最短的情況下能不能炸毀超過所有電站發(fā)電量一半的電量?

思路:因為電站數(shù)量較少,先考慮用弗洛伊德算法求出最短路徑,然后把路徑看著每個電站的體積,發(fā)電量看做電站的價值,就變成了01背包問題,最后只要判斷能否炸毀超過一半電量就可以。

code:

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define INF 0x3f3f3f3fint map[305][305];int dp[100010];int a[10010];int n,m;void flod(){ for(int k=0;k<=n;k++) for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) if(map[i][j] > map[i][k]+map[k][j]) map[i][j] = map[i][k] + map[k][j];}int main(){ int t; scanf("%d",&t); while(t--) { int x,y,z; scanf("%d%d",&n,&m); for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) { map[i][j] = INF; if(i==j) map[i][j] = 0; } for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&z); if(map[x][y] > z) { map[x][y] = z; map[y][x] = z; } } flod(); int sum = 0; int dis = 0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum += a[i]; if(map[0][i] != INF) dis += map[0][i]; } memset(dp,0,sizeof(dp)); for(int i=1;i<=n;i++) for(int j=dis;j>=map[0][i];j--) if(dp[j-map[0][i]] + a[i] > dp[j]) dp[j] = dp[j-map[0][i]] + a[i]; int flag = 0; for(int i=1;i<=dis;i++) if(dp[i] > sum / 2) { flag = 1; printf("%d/n",i); break; } if(!flag) printf("impossible/n"); } return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 全椒县| 兴和县| 宜丰县| 梓潼县| 武功县| 兴国县| 沅江市| 永年县| 靖江市| 襄城县| 山阴县| 宜黄县| 永吉县| 孟连| 教育| 手机| 平昌县| 巢湖市| 右玉县| 乐陵市| 敦煌市| 八宿县| 罗甸县| 高平市| 延寿县| 上虞市| 西贡区| 青龙| 天长市| 榆林市| 长子县| 临汾市| 沁源县| 重庆市| 理塘县| 泾川县| 绿春县| 时尚| 论坛| 惠州市| 察雅县|