50095106 drop the nuke.

Source: Internet
Author: User

50095106 drop the nuke.

"Question description"

21XX years, USSR and US broke the war, we want to USSR dismembered, so do not hesitate to use strategic nuclear missiles. You are now the commander of the strategic Strike Force, and you have received an encrypted image (N*m size) sent by the satellite, in this picture "." Representing the open space, "G" represents the Enemy Army, "#" stands for conformal (anti-nuclear weapons, anti-weapons, anti-natural threats) facilities. Your nuke is a huge equivalent and can kill all the thugs in the area. But your nuke can only be delivered to the open space, and if it encounters a conformal facility, it will no longer constitute an area of destruction (horizontal line, vertical line, the conformal facility does not constitute a killing range). Now your missile launcher is in the (3,3) position, in order to get a dismembered effect, please output the most killer mob program, and the maximum number of mobs that can be killed (evil ...). )。

"Input Requirements"

* First line: two integer n,m.
* Next is a "G" "#" "." A map that represents a satellite sent back.

"Output Requirements"

A sentence in the following format
The missiles are delivered to (x, y) and can destroy up to Z enemies.

"Input Instance"

13############# #GG. ggg#ggg.####. #G #g#g#g##.......#. g# #G #.###. #G #g# #GG. ggg.#. gg# #G #. #G #.#.#.## #G ... g.....# #G #. #G # # # # #G # # ... G#ggg. gg# #G #. #G #g#. #G # #GG. ggg#g.gg##############

"Output instance"

The missiles are delivered to (7,11), killing up to 10 enemies.

"Other Notes"

LJX that N and M will not be greater than 26.

"Analysis of Test questions"

LJX Li Jiaxin Children out of the data seems a bit pit, the format of the output is very complex in Chinese and English ~ ~ ~

Let's take a look at how to throw the enemy out at one point, of course, four simple while can be solved, the code is as follows:

int res (int i,int j) {    int sum=0,l,b;    l=i;//do not forget to back up here, otherwise I and J values will not be used later.    b=j;    while (a[l][b]!= ' # ')//When not conformal facility    {        if (a[l][b]== ' G ') sum++;//is the enemy, sum plus 1        b++;//power moves left    }    l=i;// Backup    b=j;    while (a[l][b]!= ' # ')    {        if (a[l][b]== ' G ') sum++;        b--;//move Right    }    l=i;//backup    b=j;    while (a[l][b]!= ' # ')    {        if (a[l][b]== ' G ') sum++;        l++;//move Up    }    l=i;    B=j;    while (a[l][b]!= ' # ')    {        if (a[l][b]== ' G ') sum++;        l--;    } Move the return    sum;//return result}

That's it.

Then, search for violence again:

int main () {for    (int i=0;i<n;i++)//Enumerate each point for        (int j=0;j<m;j++)        {             sum=res (i,j);             Ans=max (ans,sum);//If the result is large, replace        }     Cout<<ans;}

The two pieces of code together, plus the declaration and header file and output format is the right

Is that right?

Perhaps you have seen the loophole, if it is simply delivered to any vacant space, then the answer seems to be not a point (7,11) it?

Can try to run the above program, but also to add a record point, seemingly the upper right corner of the open space, can eliminate 11 enemies.

In fact, this is still a maze problem, of course, we can use DFS fix, the code is as follows:

void Dfs (int x,int y) {     int next[4][2]={{0,1},//toward array                     {1,0},                     {0,-1},                     { -1,0}};     int sum,tx,ty,k;     Sum=res (x, y);//Find out the answer here     if (SUM>MAXN)//Big words replace     {         maxn=sum;         mx=x;         my=y;     }     for (k=0;k<=3;k++)     {         tx=x+next[k][0];         TY=Y+NEXT[K][1];         if (tx<0 | | tx>n-1 | | ty<0 | | ty>m-1) continue;//boundary judgment         if (a[tx][ty]== '. ' && book[tx][ty]==0)// Can walk and never go to         {             book[tx][ty]=1;//tag has gone             dfs (tx,ty);//Continue Walking         }     }     return;

Code

#include <iostream>using namespace Std;char a[50][50];int maxn=-10000,book[50][50],n,m,mx,my;int res (int i,int J    ) {int sum=0,l,b;    L=i;    B=j;        while (a[l][b]!= ' # ') {if (a[l][b]== ' G ') sum++;    b++;    } l=i;    B=j;        while (a[l][b]!= ' # ') {if (a[l][b]== ' G ') sum++;    b--;    } l=i;    B=j;        while (a[l][b]!= ' # ') {if (a[l][b]== ' G ') sum++;    l++;    } l=i;    B=j;        while (a[l][b]!= ' # ') {if (a[l][b]== ' G ') sum++;    l--; } return sum;}                     void Dfs (int x,int y) {int next[4][2]={{0,1}, {1,0}, {0,-1},     { -1,0}};     int sum,tx,ty,k;     Sum=res (x, y);         if (SUM&GT;MAXN) {maxn=sum;         Mx=x;     My=y;         } for (k=0;k<=3;k++) {tx=x+next[k][0];         TY=Y+NEXT[K][1];         if (tx<0 | | tx>n-1 | | ty<0 | | ty>m-1) continue; if (a[tx][ty]== '. ' && book[tx][ty]==0) {Book[TX]             [Ty]=1;                           DFS (Tx,ty); }} return;    int main () {int i,startx=3,starty=3;    cin>>n>>m;    for (int i=0;i<n;i++) for (int j=0;j<m;j++) cin>>a[i][j];    Book[startx][starty]=1;    Maxn=res (Startx,starty);    mx=3;    my=3;    DFS (3,3); cout<< "The missile is delivered to (" <<mx<< "," <<my<< ") and can eliminate" <<maxn<< "enemies. ";}

50095106 dropping a bomb

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.