之前的思路有问题的,居然还一本正经地给它写出来了,一整个尴尬住。
如下:
0
# include <iostream>
# include <set>
using namespace std;
const int N=1000,T=1e8;
int n,S,L,cnt;
long long a,b;
set<long long> s;
pair<int,int> p[N];
int main(void) {
cin>>n>>L>>S;
for(int i=0; i<n; i++) {
cin>>a>>b;
s.insert(a*T+b);
}
int k=0;//S图中树的数量
for(int i=S; i>=0; i--)
for(int j=0; j<=S; j++) {
cin>>a;
if(a==1) {
p[k].first=i;
p[k++].second=j;
}
}
set<long long>::iterator it;
for(it=s.begin(); it!=s.end(); it++) {
a=*it/T,b=*it%T;
if(a>L-S || b>L-S)continue;
bool flag=false;
for(int i=0; i<k; i++) {
//cout<<p[i].first<<" "<<p[i].second<<endl;;
long long m=(a+p[i].first)*T+(b+p[i].second);
//cout<<m<<" "<<i<<endl;
if(s.find(m)!=s.end()) {
flag=true;
} else {
flag=false;
break;
}
}
if(flag)cnt++;
}
cout<<cnt<<endl;
return 0;
}
//这个思路有问题的
后来受到一位同学的BLOG启发,立个浅浅的flag吧。
然后再次翻车了:
10分:
# include <iostream>
using namespace std;
const int N=51,M=1000;
int n,L,S,ans;
bool b[N][N];
pair<int,int> one_location[N];
bool find(int a,int b) {
for(int i=0; i<n; i++) {
if(a==one_location[i].first && b==one_location[i].second) {
return true;
}
}
return false;
}
int main(void) {
cin>>n>>L>>S;
for(int i=0; i<n; i++)
cin>>one_location[i].first>>one_location[i].second;
for(int i=S; i>=0; i--)
for(int j=0; j<=S; j++)
cin>>b[i][j];
for(int i=0; i<n; i++) {
if(one_location[i].first>L-S || one_location[i].second>L-S)continue;
bool flag=true;
for(int x=0; x<=S; x++) {
for(int y=0; y<=S; y++) {
if(x==0 && y==0)continue;
if(b[x][y]==1 && !find(one_location[i].first+x,one_location[i].second+y)) {
flag=false;
break;
}
if(b[x][y]==0 && find(one_location[i].first+x,one_location[i].second+y)) {
flag=false;
break;
}
}
if(!flag)break;
}
if(flag)ans++;
}
cout<<ans<<endl;
return 0;
}
//10
现在是9月15日,距离上次改这道题(9月3号)已经过去了不知道多少天了,
时隔这么久,今天居然给它整过了,代码如下:
100
# include <iostream>
using namespace std;
const int N=51,M=1010;
int n,L,S,ans;
bool b[N][N];
pair<int,int> one_location[M];
int find(int a,int b) {
for(int i=0; i<n; i++) {
if(a==one_location[i].first && b==one_location[i].second) {
return 1;
}
}
return 0;
}
int main(void) {
cin>>n>>L>>S;
for(int i=0; i<n; i++)
cin>>one_location[i].first>>one_location[i].second;
for(int i=S; i>=0; i--)
for(int j=0; j<=S; j++)
cin>>b[i][j];
for(int i=0; i<n; i++) {
if(one_location[i].first>L-S || one_location[i].second>L-S)continue;
bool flag=true;
for(int x=0; x<=S; x++) {
for(int y=0; y<=S; y++) {
if(x==0 && y==0)continue;
int findx=find(one_location[i].first+x,one_location[i].second+y);
if(findx!=b[x][y]) {
flag=false;
break;
}
}
if(!flag)break;
}
if(flag)ans++;
}
cout<<ans<<endl;
return 0;
}
但是第二份代码依旧不知道错哪了。