[SCOI2005] Minesweeper Mine

Source: Internet
Author: User

1088: [SCOI2005] Minesweeper mine Time limit:10 Sec Memory limit:162 MB
submit:2028 solved:1187
[Submit] [Status] [Discuss] Description

I believe everyone has played the game of minesweeper. There are some thunder in a n*m matrix, you need to find out the ray based on some information. Halloween arrived, "Yu" People have a simple game of minesweeper, the rules of the game and the same as mine, if a lattice does not have thunder, then it is the number of the inside of the grid and its 8 connected to the number of thunder. Now the chessboard is NX2, and the first column contains some grids that are thunder, and the second column has no thunder, such as: Because the first column of thunder may have many options to meet the number of the second column limit, your task is to determine the second column according to the information of the first quagliere how many kinds of placement scheme.

Input

The first behavior n, the second row has n number, in order the number of the second column in the lattice. (1<= N <= 10000)

Output

A number, that is, the number of thunder in the first column.

Sample Input 12
1 1Sample Output 12Sample Input 2 (This is my own addition, maybe someone will be wrong)3
5 8 5Sample Output 24HINT Source[Submit][status][discuss] Analysis

  Since this is a n*2 board, if there is no mine in the second row, the first row is determined by the number of the top two squares, and the nature behind it can be handed out. It can be understood that: suppose we want to determine the number of mines in the first row (i>=3) lattice, then satisfy: first[i-2]+first[i-1]+first[i]==second[i-1]. When i==2, First[i]=second[i-1]-first[i-1] (first[2]=second[1]-first[1]), so long as the possible values of first[1] are enumerated starting at 0.

1#include <bits/stdc++.h>2 using namespacestd;3 Const intmaxn=20000;4 intn,ans=0;5 intSEC[MAXN];6 intFIR[MAXN];7 BOOLJud ();8 intMain () {9scanf"%d",&N);Ten      for(intI=1; i<=n;i++) Onescanf"%d",&sec[i]); A      for(intI=0; i<=sec[1];i++){ -memset (Fir,0,sizeof(FIR)); -fir[1]=i; thefir[2]=sec[1]-i; -         if(Jud () = =true){ -ans++; -         } +     } -cout<<ans; +     return 0; A } at BOOLJud () { -      for(intI=3; i<=n+1; i++){ -fir[i]=sec[i-1]-fir[i-2]-fir[i-1]; -     } -     if(fir[n+1])return false; -     return true; in}

  Special CAUTION:

  The 27th line of fir[n+1] can absolutely not be changed to fir[n+1]>0, because there may be negative values, such as the example I gave above sample 2. 5 8 5 is the second row, and the first line can roll out 1 4 3-2. I've been here many times because of this WA. But, write Fir[n+1]!=0 is beyond all doubt√ of, all blame my hand cheap ...

[SCOI2005] Minesweeper Mine

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.