[LINK] I am a link. Click me :)
Question]
Enter the question here
[Question]
Pay attention to the number of asterisks...
Then v x y is connected from (Y, x) to (Y + 1, x.
H x Y is the line from (x, y) to (x, y + 1 ).
(X, Y) is used as the upper left corner of the enumeration.
[Code]
#include <bits/stdc++.h>using namespace std;const int N = 10;int n,m;bool a[N+10][N+10][2];int cnt[N+5];bool check(int x,int y,int p){ for (int i = 1;i <= p;i++) if (a[x][y][0]){ y++; if (y>n) break; }else return 0; for (int i = 1;i <= p;i++) if (a[x][y][1]){ x++; if (x>n) break; }else return 0; for (int i = 1;i <= p;i++) if (y-1>=1 && a[x][y-1][0]){ y--; if (y<1) break; }else return 0; for (int i = 1;i <= p;i++) if (x-1>=1 && a[x-1][y][1]){ x--; if (x<1) break; }else return 0; return 1;}int main(){ //freopen("/home/ccy/rush.txt","r",stdin); //freopen("/home/ccy/rush_out.txt","w",stdout); ios::sync_with_stdio(0),cin.tie(0); int kase = 0; while (cin >> n){ if (kase>0){ cout<<endl; cout<<"**********************************"<<endl; cout<<endl; } cout<<"Problem #"<<++kase<<endl<<endl; memset(a,0,sizeof a); memset(cnt,0,sizeof cnt); cin >> m; for (int i = 1;i <= m;i++){ char s[5];int x,y; cin >> s >> x >> y; if (s[0]=='H') a[x][y][0] = 1; else{ swap(x,y); a[x][y][1] = 1; } } for (int p = 1;p <= n;p++) for (int i = 1;i <= n;i++) for (int j = 1;j <= n;j++) if (check(i,j,p)) cnt[p]++; bool none = 1; for (int i = 1;i <= n;i++){ if (cnt[i]>0) { none = 0; cout<<cnt[i]<<" square (s) of size "<<i<<endl; } } if (none) cout<<"No completed squares can be found."<<endl; } return 0;}
Exercise 4-2 uva201 squares