-
3 5 5 #.... ..... ...#. ..... .#... 5 5 ....# ..... ..... #.... ....# 5 6 .....# ...... #..... ...... ....#. 10 10 .......#.. .......... ..#....... .......... ......#... .......... .......... ..#....... ......#... ..........
样例输出
-
No Yes Yes
描述
Recently Little Hi started to like astronomy and downloaded the pictures of K constellations. He wonders how many of them he can spot in the night?
输入
Line 1: K(1 <= K <= 20), the number of constellations.
K constellation pictures follow. The format of each picture is:
Line 1 of each picture: H and W(5 <= H, W, <= 100), the height and width of the picture.
Line 2~H+1 of each picture: An H*W matrix of characters representing the picture of a constellation. Each line contains W characters. '#' for a star and '.' for empty area. There are no more than 20 stars in each constellation.
After K constellations is the sky Little Hi looks to in the night.
Line 1 of sky: N and M(100 <= N, M <= 1000), the size of the sky Little Hi looks to.
Line 2~N of sky: An N*M matrix of characters representing the sky Little Hi looks to. Each line contains M characters. '#' for a star and '.' for empty area. There are no more than 5000 stars in the sky.
输出
For each constellation in the Input output "Yes" or "No" indicating whether Little Hi can spot the constellation in the sky.
All pictures of constellations and the sky Little Hi looks to are in the same direction so there is no need to rotate the pictures.
提示
A constellation can be spoted if and only if all stars in the constellation can be matched in the sky. It is allowed that two spoted constellations share common stars.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
int k;
cin >> k;
vector<vector<string>>con;
while (k--)
{
vector<string>tmp;
int w, h;
cin >> w >> h;
char a;
for (int i = 0; i < w; i++)
{
string s;
cin >> s;
tmp.push_back(s);
}
con.push_back(tmp);
}
int w1, h1;
cin >> w1 >> h1;
char b;
vector<string>finc;
vector<vector<int>>visit;
for (int i = 0; i < w1; i++)
{
string ss;
cin >> ss;
finc.push_back(ss);
}
int flag;
for (int i1 = 0; i1 < con.size(); i1++)
{
visit.clear();
for (int i = 0; i < w1; i++)
{
vector<int>v1;
for (int j = 0; j < h1; j++)
{
v1.push_back(0);
}
visit.push_back(v1);
}
vector<string>tmp = con[i1];
int row = 0;
int count_row = -1;
flag = 0;
for (int i = 0;i < finc.size()-tmp.size()+1; i++)
{
if (i >= finc.size())
break;
for (int j = 0; j < w1 - tmp[0].size() + 1;)
{
if (i >= finc.size())
break;
//cout << "i,j " << i << " " << j << endl;
if (visit[i][j] == 0)
{
if (tmp[row] == finc[i].substr(j, tmp[row].size())) //怎么可以直接比较呢
{
visit[i][j] = 1;
if (row == 0)
{
//cout << "row=0, i= " << i << endl;
count_row = i; //记录纵向比较时最初的行数
}
i++;
row++;
if (row == tmp.size()) //比较到最后一行也相等的则输出YES
{
flag = 1;
break;
}
}
else
{
visit[i][j] = -1;
j++;
row = 0;
if (count_row != -1)
{
i = count_row; //恢复纵向比较最初的行数
count_row = -1;
}
if (j == finc[0].size() - tmp[0].size() + 1)
{
j = 0;
i++;
}
}
}
else
j++;
}
if (flag == 1)
{
cout << "Yes" << endl;
break;
}
}
if (flag!=1)
cout << "No" << endl;
}
system("pause");
return 0;
}
忽视了一个重大问题好么!!!!那些星座之间有可能重叠的好么,不仅仅是共用某个星星。所以这样依次比较string是否完全相等根本就是错误的好么!!!
bool star_com(string a, string b)
{
int len = a.size();
for (int i = 0; i < len; i++)
{
if (a[i] == '#')
{
if (b[i] != '#')
return false;
}
}
return true;
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool star_com(string a, string b)
{
int len = a.size();
for (int i = 0; i < len; i++)
{
if (a[i] == '#')
{
if (b[i] != '#')
return false;
}
}
return true;
}
int main()
{
int k;
cin >> k;
vector<vector<string>>con;
while (k--)
{
vector<string>tmp;
int w, h;
cin >> w >> h;
char a;
for (int i = 0; i < w; i++)
{
string s;
cin >> s;
tmp.push_back(s);
}
con.push_back(tmp);
}
int w1, h1;
cin >> w1 >> h1;
char b;
vector<string>finc;
for (int i = 0; i < w1; i++)
{
string ss;
cin >> ss;
finc.push_back(ss);
}
int flag;
for (int i1 = 0; i1 < con.size(); i1++)
{
vector<string>tmp = con[i1];
int row = 0;
int count_row = -1;
flag = 0;
for (int i = 0; i < finc.size() - tmp.size() + 1; i++)
{
if (i >= finc.size())
break;
for (int j = 0; j < w1 - tmp[0].size() + 1;)
{
if (i >= finc.size())
break;
if (star_com(tmp[row], finc[i].substr(j, tmp[row].size())))
{
if (row == 0)
count_row = i;
i++;
row++;
if (row == tmp.size())
{
flag = 1;
break;
}
}
else
{
j++;
row = 0;
if (count_row != -1)
{
i = count_row;
count_row = -1;
}
if (j == finc[0].size() - tmp[0].size() + 1)
{
j = 0;
i++;
}
}
}
if (flag == 1)
{
cout << "Yes" << endl;
break;
}
}
if (flag != 1)
cout << "No" << endl;
}
system("pause");
return 0;
}
#include <iostream>
using namespace std;
struct point
{
int x, y;
};
struct con
{
int total_p; //统计小图中星星的数量
point p[20];
}conl[20];
char finc[1000][1000];
int main()
{
int k;
cin >> k;
int count = 0;
for (int K = 0; K < k;K++)
{
int w, h;
cin >> w >> h;
char a;
conl[K].total_p = 0;
int xx,yy;
for (int i = 0; i < w; i++)
{
for (int j = 0; j < h; j++)
{
cin >> a;
if (a == '#')
{
if (conl[K].total_p == 0)
{
xx = i;
yy = j;
conl[K].total_p = 1;
}
else
{
conl[K].p[conl[K].total_p].x = i - xx;
conl[K].p[conl[K].total_p++].y = j - yy; //存储相对位置
}
}
}
}
}
int w1, h1;
cin >> w1 >> h1;
for (int i = 0; i < w1; i++)
{
for (int j = 0; j < h1; j++)
cin >> finc[i][j];
}
for (int K = 0; K< k; K++)
{
int f2 = -1;
for (int i = 0; i < w1&&f2!=0; i++)
{
for (int j = 0; j < h1&&f2 != 0; j++)
{
if (finc[i][j] == '#')
{
int flag = 1;
for (int m = 0; m < conl[K].total_p; m++)
{
int xx = conl[K].p[m].x + i;
int yy = conl[K].p[m].y + j;
if (finc[xx][yy] != '#' || xx >= w1 || yy >= h1)
{
flag = 0;
break;
}
}
if (flag == 1)
{
f2 = 0;
}
}
}
}
if (f2 == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
system("pause");
return 0;
}