首页 > ACM题库 > HDU-杭电 > hdu 3636 Escape from Zirong forest待解决[解题报告]C++
2014
11-29

hdu 3636 Escape from Zirong forest待解决[解题报告]C++

Escape from Zirong forest

问题描述 :

Now SuSu and his companions arrived at Xiangling’s hometown – ZiRong Forest. To drive SuSu out of these area, "Piaorou Bro" Lingduan set the forest on fire. To prevent the trees from burning down, SuSu must find the exit of the forest as quickly as possible and kill Lingduan. If he could not kill Lingduan in TIME seconds, the forest will suffer too much damage to be recovered. What was worse, there are some horrible monsters in the forest. SuSu would suffer a certain damage when he kill a monster on his way to the exit. For the purpose of save energy and to kill Lingduan more easily, the damage SuSu suffer from the monsters should be the fewer the better. Please help SuSu to find a reasonable path which can lead him to the exit in TIME seconds, and suffers the minimum damage at the same time.
City Planning

To represents the ZiRong forest, we use a n * m maze:
‘S’ and ‘L’ represents the position of SuSu and Lingduan at the very beginning. Each of them appears in the maze once and only once.
‘F’ represents fire where SuSu can not step into.
A number (from 0 to 9) indicates there is one monster in this grid ,and it’s attack is the corresponding number.

Every second SuSu can choose a direction and go forward 1 ~ K steps, and for all monsters’ attack in the grids he passed by(if the grid do exist a monster), we accumulate them and get a sum. The damage SuSu will suffer is the square of this sum.

输入:

The first line of input should give the number of cases, T(1<=T<=50).
The first line of each case are four numbers N, M, TIME, K. (2 <= N, M <= 100, 1 <= TIME, K <= 100)
Followed by N lines each with M characters, described the ZiRong forest.

输出:

The first line of input should give the number of cases, T(1<=T<=50).
The first line of each case are four numbers N, M, TIME, K. (2 <= N, M <= 100, 1 <= TIME, K <= 100)
Followed by N lines each with M characters, described the ZiRong forest.

样例输入:

5
3 3 2 2
S19
111
F1L
3 3 3 2
S19
111
F1L
5 4 5 1
S111
9FF1
9FF1
9111
FFLF
5 4 4 100
S111
9FF1
9FF1
9111
FFLF
5 4 100 1
S111
9FF1
9FF1
9111
FFLF

样例输出:

Case 1: 101
Case 2: 5
Case 3: 胜败兵家事不期 卷土重来是大侠
Case 4: 19
Case 5: 7


  1. /*
    * =====================================================================================
    *
    * Filename: 1366.cc
    *
    * Description:
    *
    * Version: 1.0
    * Created: 2014年01月06日 14时52分14秒
    * Revision: none
    * Compiler: gcc
    *
    * Author: Wenxian Ni (Hello World~), [email protected]
    * Organization: AMS/ICT
    *
    * =====================================================================================
    */

    #include
    #include

    using namespace std;

    int main()
    {
    stack st;
    int n,i,j;
    int test;
    int a[100001];
    int b[100001];
    while(cin>>n)
    {
    for(i=1;i>a[i];
    for(i=1;i>b[i];
    //st.clear();
    while(!st.empty())
    st.pop();
    i = 1;
    j = 1;

    while(in)
    break;
    }
    while(!st.empty()&&st.top()==b[j])
    {
    st.pop();
    j++;
    }
    }
    if(st.empty())
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
    }

  2. #include <cstdio>

    int main() {
    //answer must be odd
    int n, u, d;
    while(scanf("%d%d%d",&n,&u,&d)==3 && n>0) {
    if(n<=u) { puts("1"); continue; }
    n-=u; u-=d; n+=u-1; n/=u;
    n<<=1, ++n;
    printf("%dn",n);
    }
    return 0;
    }