#1114: Little Hi Little Ho's big battle: Minesweeper • Time limit: 10000ms single point limit: 1000ms memory limit: 256MB description
Story background: The Chamber of Secrets, monitors and crisis-filled squares
"Let's start with a simple question:" Little Hi thinks for a moment: "In a square with a size of 2*n, where the first row of some lattice may have at most one mine, and the second row of squares is all numbers, Indicates the total number of mines in the first row of the lattice not exceeding 2 of the lattice, that is, the number in the second row of the first grid of the i-1, I, i+1, three lattice (if I=1 or n does not necessarily have three) of mine. ”
"And what we're going to do is--find out where it must be, and where it's not Ray ." Little ho Way: "Otherwise, I will be glorious sacrifice." ”
Tip: Find the key points--those that can make the situation look better once they decide.
Input
There are multiple sets of test data for each test point (input file).
The first behavior of each test point is an integer task that represents the number of groups of test data.
In a set of test data:
The 1th behavior is 1 integer n, which indicates the width of the maze.
2nd Act n Integer a_1 ... A_n, which in turn represents the number labeled in N squares of the second row of the maze.
For 100% of data, meet 1<=n<=10^5, 0<=a_i<=3.<>
For 100% of data, maps that meet the data description must exist.
Output
For each set of test data, output 2 lines, where the first line will first output the number of grid must be a mine, and then according to the order from small to large to output all the location of the grid must be mine, the second line first output a certain number of non-mine lattice, according to the order from small to large output all must not be the location of the
-
Sample input
-
-
Sample output
-
Ideas:
Use DFS deep search, find the ANS array, for the existence of a variety of answers, not all are 0 or not all 1, to 2, output, output all the 0,1 position.
AC Code:
1#include <iostream>2#include <stdio.h>3#include <string.h>4 #defineMAX 1000055 using namespacestd;6 7 intN, A[max],up[max],ans[max];8 9 voidDfsintPOS)Ten { One if(pos = = n+1) A { - for(inti =1; I <= N; i++) - { the if(ans[i]==-1) Ans[i] =Up[i]; - Else if(Ans[i]! = Up[i]) ans[i] =2;//There are several possible cases, if not all 0, or not all 1, to 2. - } - return; + } - + for(inti =0; I <2; i++) A { atUp[pos] =i; - if(Up[pos] + Up[pos-1]>A[pos]) - Continue; - - if(Pos >1&& Up[pos] + up[pos-1] + Up[pos-2]! = A[pos-1]) - Continue; in - if(pos = = n && up[pos] + up[pos-1] !=A[pos]) to Continue; + -DFS (POS +1); the } * } $ Panax Notoginseng intMain () - { the inttask; +CIN >>task; A while(task--) the { + intx=0, o=0; - $CIN >>N; $ for(inti =1; I <= N; i++) - { -CIN >>A[i]; the } -memset (ans,-1,sizeof(ans));WuyiDfs1); the - for(inti =1; I <= N; i++) Wu { - if(Ans[i] = =0) Abouto++; $ Else if(Ans[i] = =1) -X + +; - } - Acout <<x; + for(inti =1; I <= N; i++){ the if(Ans[i] = =1) -cout <<" "<<i; $ } thecout <<Endl; thecout <<o; the for(inti =1; I <= N; i++){ the if(Ans[i] = =0) -cout <<" "<<i; in } thecout <<Endl; the } AboutSystem"Pause"); the}
Hiho #1114: Little Hi Little Ho's big battle: Minesweeper • One