先上题目:
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
1
3 2
1 2 1
3 1 3
Sample Output
5
impossible
题意:有一堆电站(n个),你有一个基地(0号),每个电站有一点的供电量,给你关于电站和你的基地的无向图,现在需要你控制一部分电站,使得控制的电站的供电量大于总供电量的一半,同时由于控制一个电站需要的一辆坦克,一辆坦克没有一个单位的距离需要一单位的油,问能否可以达到要求,如果可以达到要求,最少需要多少的油。
这是一题最短路+01背包。首先求出到每一个电站的距离,然后总供电量作为背包的容量,跑一次01背包以后在大于一般供电量的那个供电量开始向总供电量方向扫描找出最小值,这里需要注意的是一定是 大于总供电量的一半。
这题因为敲的时候因为有一个地方将+=写成=+,结果算上另一个小错误加起来WA了10+次(┬_┬) 。
上代码:
1 #include2 #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