标签:stream his memset this out iostream graph mes count
1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstring> 5 #include <vector> 6 using namespace std; 7 const int maxn = 30; 8 struct Point{ 9 int x; 10 int y; 11 int sign; //方向 12 int count; //个数 13 Point(int x = 0,int y = 0,int sign = 0,int count = 0){ 14 this->x = x; 15 this->y = y; 16 this->sign = sign; 17 this->count = count; 18 } 19 }; 20 int graph[maxn][maxn]; 21 int have_find[maxn][maxn]; //-1为未标记,1为已标记 22 int m,n,count; 23 vector<Point*> point; //存放需要消除的点 24 void finded(Point* p){ //标记已经确定消除的点 25 int x = p->x; 26 if(p->sign == 1){ 27 for(int i = p->y;i < p->y+p->count;i++){ 28 have_find[p->x][i] = 1; 29 } 30 }else if(p->sign == 2){ 31 for(int i = p->x;i < p->x+p->count;i++){ 32 have_find[i][p->y] = 1; 33 } 34 } 35 } 36 void judge(int x,int y,int s){ //判断以点(x,y)为首的行(列)是否符合消除条件 37 int count = 0; //根据s的值来判断是行遍历还是列遍历 38 int temp = graph[x][y]; //s == 1为行遍历,s == 2为列遍历 39 if(s == 1){ //行遍历 40 for(int i = y;i < m;i++){ 41 if(graph[x][i] == temp){ 42 count++; 43 }else{ 44 break; 45 } 46 } 47 }else if(s == 2){ //列遍历 48 for(int i = x;i < n;i++){ 49 if(graph[i][y] == temp){ 50 count++; 51 }else{ 52 break; 53 } 54 } 55 } 56 if(count >= 3){ 57 Point* p = new Point(x,y,s,count); 58 finded(p); //标记已经确定消除的点 59 point.push_back(p); 60 } 61 } 62 63 void make_work(){ //消除掉所有标记的点 64 for(int i = 0;i < point.size();i++){ 65 Point* p = point[i]; 66 if(p->sign == 1){ 67 for(int i = p->y;i < p->y + p->count;i++){ 68 graph[p->x][i] = 0; 69 } 70 }else if(p->sign == 2){ 71 for(int i = p->x;i < p->x + p->count;i++){ 72 graph[i][p->y] = 0; 73 } 74 } 75 } 76 } 77 int main(){ 78 cin >> n >> m; 79 for(int i = 0;i < n;i++){ 80 for(int j = 0;j < m;j++){ 81 cin >> graph[i][j]; 82 } 83 } 84 memset(have_find,-1,sizeof(have_find)); 85 86 for(int i = 0;i < n;i++){ //进行行标记 87 for(int j = 0;j < m;j++){ 88 if(have_find[i][j] == -1){ 89 judge(i,j,1); 90 } 91 } 92 } 93 memset(have_find,-1,sizeof(have_find)); 94 for(int i = 0;i < n;i++){ //进行列标记 95 for(int j = 0;j < m;j++){ 96 if(have_find[i][j] == -1){ 97 judge(i,j,2); 98 } 99 } 100 } 101 make_work(); //进行清除 102 for(int i = 0;i < n;i++){ 103 for(int j = 0;j < m;j++){ 104 cout << graph[i][j] << " "; 105 } 106 cout << "\n"; 107 } 108 return 0; 109 }
标签:stream his memset this out iostream graph mes count
原文地址:https://www.cnblogs.com/awei-diamond/p/12599997.html