"Hiho" Hiho the 29th week • Minesweeper I

Source: Internet
Author: User

Title Description:

Roughly, give you a sequence of length n, the number on each sequence represents how many mines are within a radius of 2, ask you how many positions you can determine at most, and output certain number of thunder and position sequence, no number of thunder and position sequence

Ideas:

The problem data range is not very large, O (n) Bar

After the first position is determined, according to Arr[1], the second position is determined

Similarly, for Arr[2], the third position is determined ....

But WA two times, because he asked is sure!

Here is a situation where the first bit of lightning and no thunder are feasible, then although satisfied, but some locations are uncertain!

So Flag1,flag2 is going to have to convict.

By the way, vector is good.

Attached code:

#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <string>#include <math.h>#include <stack>#include <queue>#include <vector>#include <map>#include <set> #pragma warning (disable:4996) #define Zero (a) memset (a, 0, sizeof (a)) #define NEG (a) memset (a,-1, sizeof (a)) #define ALL (a) A.begin (), A.end () #define PB push_back#define REPF (i,a,b) for (i = a;i <= b; i++) #define Lson L , m,rt<<1#define Rson m+1,r,rt<<1|1#define root 1,n,1#define ll long long#define maxn 100005#define mod 100000 0007using namespaceStd;intN, Num[maxn];intRay1[maxn],ray2[maxn];vector<int>Has, nhave;bool rraay (int temp, intA[]) {a[0] = 0; A[1] =Temp for (int i = 2; I <= N; i++) {A[i] = num[i-1]-a[i-1]-a[i-2]; if (a[i]>1 | | a[i]<0) return False; } if (num[n] = = A[n] + a[n-1]) return True; else return False;} voidInit () {scanf ("%d", &n); Have.clear (); Nhave.clear (); for (int i = 1; I <= N; + +)i) {scanf ("%d", &Num[i]); }}voidPT () {int len =Have.size (); printf ("%d", Len); for (int i = 0; i < Len; + +i) {printf ("%d", Have[i]); } printf ("\ n"); Len =Nhave.size (); printf ("%d", Len); for (int i = 0; i < len; + +  i) {printf ("%d" , Nhave[i]);} printf ("\ n" );} void  Solve () {bool Flag1 = rraay (0 , ray1), bool Flag2 = rraay (1 , ray2); if (Flag1 &&!  Flag2) {for (int i = 1; I <= N; + +  i) {if (ray1[i] = = 1 ) have.push_back (i); else  nhave.push_back (i);} if (!flag1 &&  flag2) {for (int i = 1; I <= N; + +  i) {if (ray2[i] = = 1 ) have.push_back (i); e LSE  Nhave.push_back (i);}} if (Flag1 &&  flag2) {for (int i = 1; I <= N; + +  i) {if (ray1[i] = =  Ray2[i]) {if (ray1[i] = = 1< span>) Have.push_back (i); else  nhave.push_back (i);}} } PT ();} int  Main () {int  t; scanf ("%d", &  t), while (t--) {init (); Solve ();} return 0 ;}   

"Hiho" Hiho the 29th week • Minesweeper I

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.