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