//Hello. I‘m Peter.
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define peter cout<<"i am peter"<<endl
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define N 120
int n,m,lenset;
struct Data{
int r,c;
int sumval;
}data[N*N];
int numdata;
inline bool comp(const Data a,const Data b){
return a.sumval>b.sumval;
}
int vis[N][N],nowkase;
inline bool legal(int x,int y){
return x>=0&&x<n&&y>=0&&y<m;
}
class Coversta{
public:
int cal(vector<string>&a,vector<int>&x,vector<int>&y,int x1,int y1,int x2,int y2){
nowkase++;
int sumval=0;
for(int i=0;i<lenset;i++){
int zx=x1+x[i];
int zy=y1+y[i];
if(!legal(zx,zy)) continue;
if(vis[zx][zy]!=nowkase){
vis[zx][zy]=nowkase;
sumval+=a[zx][zy]-‘0‘;
}
}
for(int i=0;i<lenset;i++){
int zx=x2+x[i];
int zy=y2+y[i];
if(!legal(zx,zy)) continue;
if(vis[zx][zy]!=nowkase){
vis[zx][zy]=nowkase;
sumval+=a[zx][zy]-‘0‘;
}
}
return sumval;
}
int place(vector <string> a, vector <int> x, vector <int> y){
memset(vis,-1,sizeof(vis));
nowkase=0;
lenset=(int)x.size();
n=(int)a.size();
m=(int)a[0].length();
numdata=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
int sumval=0;
for(int k=0;k<lenset;k++){
int zx=i+x[k];
int zy=j+y[k];
if(!legal(zx,zy)) continue;
int val=a[zx][zy]-‘0‘;
sumval+=val;
}
int t=++numdata;
data[t].r=i,data[t].c=j,data[t].sumval=sumval;
}
}
int ans=-1;
sort(data+1,data+1+numdata,comp);
numdata=min(numdata,91);
for(int i=1;i<=numdata;i++){
for(int j=1;j<=numdata;j++){
if(i==j) continue;
ans=max(ans,cal(a,x,y,data[i].r,data[i].c,data[j].r,data[j].c));
}
}
return ans;
}
};
//Hello. I‘m Peter.
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<cctype>
#include<ctime>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define peter cout<<"i am peter"<<endl
#define INT (0x3f3f3f3f)*2
#define LL (0x3f3f3f3f3f3f3f3f)*2
#define N 120
int n,m,lenset;
vector<string>at;
struct Data{
vector<pair<int,int> >v;
int sumval;
}data[N][N];
struct Data2{
int x,y,sumval;
friend bool operator<(const Data2 A,const Data2 B){
if(A.sumval!=B.sumval) return A.sumval>B.sumval;
else if(A.x!=B.x) return A.x<B.x;
else return A.y<B.y;
}
}data2;
set<Data2>se;
int vis[N][N],nowkase;
inline bool legal(int x,int y){
return x>=0&&x<n&&y>=0&&y<m;
}
class Coversta{
public:
int cal(int x1,int y1,int x2,int y2){
nowkase++;
int len,sumval=0;
len=(int)data[x1][y1].v.size();
for(int i=0;i<len;i++){
int x=data[x1][y1].v[i].first;
int y=data[x1][y1].v[i].second;
if(vis[x][y]!=nowkase){
vis[x][y]=nowkase;
sumval+=at[x][y]-‘0‘;
}
}
len=(int)data[x2][y2].v.size();
for(int i=0;i<len;i++){
int x=data[x2][y2].v[i].first;
int y=data[x2][y2].v[i].second;
if(vis[x][y]!=nowkase){
vis[x][y]=nowkase;
sumval+=at[x][y]-‘0‘;
}
}
return sumval;
}
int place(vector <string> a, vector <int> x, vector <int> y){
memset(vis,-1,sizeof(vis));
nowkase=0;
at=a;
lenset=(int)x.size();
n=(int)a.size();
m=(int)a[0].length();
se.clear();
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
data[i][j].v.clear();
int sumval=0;
for(int k=0;k<lenset;k++){
int zx=i+x[k];
int zy=j+y[k];
if(!legal(zx,zy)) continue;
pair<int,int>p=make_pair(zx,zy);
int val=a[zx][zy]-‘0‘;
sumval+=val;
data[i][j].v.push_back(p);
}
data[i][j].sumval=sumval;
data2.x=i,data2.y=j,data2.sumval=sumval;
se.insert(data2);
}
}
int ans=-1;
queue<Data2>q;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
while(!q.empty()) q.pop();
for(int k1=0;k1<lenset;k1++){
int zx1=i+x[k1];
int zy1=j+y[k1];
if(!legal(zx1,zy1)) continue;
for(int k2=0;k2<lenset;k2++){
if(k1==k2) continue;
int zx2=zx1-x[k2];
int zy2=zy1-y[k2];
if(!legal(zx2,zy2)) continue;
data2.x=zx2,data2.y=zy2,data2.sumval=data[zx2][zy2].sumval;
if(se.find(data2)!=se.end()){
q.push(data2);
se.erase(data2);
}
}
}
data2.x=i,data2.y=j,data2.sumval=data[i][j].sumval;
if(se.find(data2)!=se.end()){
q.push(data2);
se.erase(data2);
}
int anst=-1;
if(!se.empty()){
anst=data[i][j].sumval;
anst+=((*se.begin()).sumval);
ans=max(ans,anst);
}
while(!q.empty()){
if(i!=q.front().x||j!=q.front().y){
anst=cal(i,j,q.front().x,q.front().y);
ans=max(ans,anst);
}
se.insert(q.front());
q.pop();
}
}
}
return ans;
}
};
原文地址:http://blog.csdn.net/uestc_peterpan/article/details/46369245