首页 > ACM题库 > HDU-杭电 > hdu 3261 Zombies VS Plants待解决[解题报告]C++
2014
03-13

hdu 3261 Zombies VS Plants待解决[解题报告]C++

Zombies VS Plants

问题描述 :

Facer was addicted to a popular game called “Plants VS Zombies”. After Facer had completed all missions, he started to play the zombies’ role to destroy plants and called the new game “Zombies VS Plants”.

In the game “Zombies VS Plants”, there are 3 kinds of zombies: Little Zombie, Adult Zombie and Football player. Different zombies have different price and different “attacking value” indicating the capability to attack, as shown in the table below:

Facer is learning to swim

Spiders also can destroy the plants. Every spider costs 125 dollars.

There are 4 kinds of plants: Sunflower, Bean, Magnet and Lettuce. Every plant has a “defending value” indicating it’s capability of defense.

Facer’s mission is to destroy ALL the plants in the field. In order to destroy plants, Facer needs to buy zombies or spiders and put them into the field. The plants field can be considered as a 5×5 grid(of course 25 cells), as shown in the figure below:

Facer is learning to swim

There is a plant in every cell. Facer can destroy plants only by two ways:

1.  If Facer puts one or more zombies together into a row of the field, and the sum of those zombies’ attacking values is larger than the sum of defending values of the plants in the same row, all plants in that row will be destroyed.

2.  Putting a spider in a cell will destroy the plant in it. But there are some exceptions as shown in the description of plant “Lettuce” in a table below.

Once a zombie is put into the plants field, it dies immediately after destroying the plants. So does a spider. In other words, Facer can use a zombie or a spider only once.

This is a table describing the features of different kinds of plants:

Facer is learning to swim

Facer can earn P1 dollars after destroying a row of plants, and destroying a sunflower will earn extra P2 dollars for him. Facer has P3 dollars but no zombies and no spiders at the begging. Of course Facer can use the money he earned to buy zombies and spiders.

Your job is helping Facer to accomplish his mission and keep money as much as possible after the mission.

输入:

There are multiple test cases.
The first line in the input is a integer T indicating the number of test cases.( 1< T <= 400 )

For each test case:
First line contains three integers P1, P2 and P3 ( 0 <= P1, P2, P3 <= 10000), meaning that Facer earns P1 dollars after destroying a row of plants and earns P2 dollars after destroying a sunflower, and Facer has P3 dollars at the beginning.
Following are 5 lines describing the plants field by top to bottom order. Each line contains 5 integers, telling what’s in the cells of a row, by left to right order. For those 5 integers:
“1” represents a sunflower.
“2” represents a bean.
“3” represents a magnet.
“4” represents a lettuce.

输出:

There are multiple test cases.
The first line in the input is a integer T indicating the number of test cases.( 1< T <= 400 )

For each test case:
First line contains three integers P1, P2 and P3 ( 0 <= P1, P2, P3 <= 10000), meaning that Facer earns P1 dollars after destroying a row of plants and earns P2 dollars after destroying a sunflower, and Facer has P3 dollars at the beginning.
Following are 5 lines describing the plants field by top to bottom order. Each line contains 5 integers, telling what’s in the cells of a row, by left to right order. For those 5 integers:
“1” represents a sunflower.
“2” represents a bean.
“3” represents a magnet.
“4” represents a lettuce.

样例输入:

2
100 100 10000
2 2 2 2 2
2 3 2 2 2
3 3 4 3 2
2 3 2 2 2
2 2 2 2 2
0 0 0
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2

样例输出:

9025
-1


  1. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。

  2. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。

  3. #include <stdio.h>
    int main()
    {
    int n,p,t[100]={1};
    for(int i=1;i<100;i++)
    t =i;
    while(scanf("%d",&n)&&n!=0){
    if(n==1)
    printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
    else {
    if(n%4) p=n/4+1;
    else p=n/4;
    int q=4*p;
    printf("Printing order for %d pages:n",n);
    for(int i=0;i<p;i++){
    printf("Sheet %d, front: ",i+1);
    if(q>n) {printf("Blank, %dn",t[2*i+1]);}
    else {printf("%d, %dn",q,t[2*i+1]);}
    q–;//打印表前
    printf("Sheet %d, back : ",i+1);
    if(q>n) {printf("%d, Blankn",t[2*i+2]);}
    else {printf("%d, %dn",t[2*i+2],q);}
    q–;//打印表后
    }
    }
    }
    return 0;
    }