Test instructions: There are two brushes, a brush red, a brush blue, the direction of the red is southeast, the direction of the blue is northwest, red plus blue equals green, now known the current state of the wall, ask from the white wall to this state at least how many times to brush
Analysis: Multi-school problems, so although I initially felt that the direct simulation of no skill, or have been afraid to hand. 1 A very happy, come on!
Code:
#include <cstdio> #include <string> #include <iostream>using namespace Std;int t,n;string a[100];int Main () {cin>>t;while (t--) {cin>>n;int tot=0;for (int i=0;i<n;i++) Cin>>a[i];int m=a[0].length (); for (int i=0;i<n;i++) {for (int j=0;j<m;j++) {if (a[i][j]== ' B ' | | a[i][j]== ' B ') {tot++;for (int k=1;i+k<n&&j-k>=0;k++) {if (a[i+k][j-k]== ' B ' | | a[i+k][j-k]== ' B ') a[i+k][j-k]= '. '; else if (a[i+k][j-k]== ' G ') a[i+k][j-k]= ' r '; else break;}} else if (a[i][j]== ' R ' | | a[i][j]== ' R ') {tot++;for (int k=1;i+k<n&&j+k<m;k++) {if (a[i+k][j+k]== ' R ' | | a[i+k][j+k]== ' R ') a[i+k][j+k]= '. '; else if (a[i+k][j+k]== ' G ') a[i+k][j+k]= ' B '; else break;}} else if (a[i][j]== ' G ') {tot+=2; for (int k=1;i+k<n&&j-k>=0;k++) {if (a[i+k][j-k]== ' B ' | | a[i+k][j-k]== ' B ') a[i+k][j-k]= '. '; else if (a[i+k][j-k]== ' G ') a[i+k][j-k]= ' R '; else break; } for (int k=1;i+k<n&&j+k<m;k++) {if (a[i+k][j+k]== ' R ' | | a[i+k][j+k]== ' R ') a[i+k][j+k]= '. '; else if (a[i+k][j+k]== ' G ') a[i+k][j+k]= ' B '; else break; }}}}cout<<tot<<endl;}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 53,192 Brush Wall problem (multi-school)-Direct simulation