【链接】 我是链接,点我呀:)
【题意】
【题解】
注意那个星号的数量。。。 然后V x y的话,是从(y,x)向(y+1,x)连线。 H x y才是从(x,y)向(x,y+1)连线 枚举以(x,y)作为左上角的举行就ok了【代码】
#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;
}