2333
Posted vimin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2333相关的知识,希望对你有一定的参考价值。
include
include
include
include
include
using namespace std;
int T,Q,n,m;
int H[1002][1002],xu[1002][1002],fa[1000005];
int fx[5]={0,0,0,1,-1},fy[5]={0,1,-1,0,0};
struct node{
int id,day,as;
}q[100005];
struct D{
int x,y,h,id,as,ids;
}d[1000005],ton[1000005];
bool cmp(node a,node b){
return a.day >b.day ;
}
bool cmp1(D a,D b){
return a.h >b.h ;
}
bool cmp2(node a,node b){
return a.id <b.id ;
}
int find(int x){
if(x==fa[x]) return x;
return fa[x]=find(fa[x]);
}
inline int read(){
int s=0,w=1; char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘) w=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘) s=s10+ch-‘0‘,ch=getchar();
return sw;
}
int main(){
T=read();
// scanf("%d",&T);
while(T--){
memset(H,0,sizeof(H));
memset(d,0,sizeof(d));
memset(fa,0,sizeof(fa));
n=read();m=read();
int res=0,ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
int xx;
xx=read();
H[i][j]=xx;
d[++res].id=res;
fa[res]=res;
d[res].x=i;
d[res].y=j;
d[res].h=xx;
xu[i][j]=res;
}
sort(d+1,d+res+1,cmp1);
// for(int i=1;i<=res;i++){
// cout<<
// }
Q=read();
for(int i=1;i<=Q;i++) q[i].day =read(),q[i].id =i;
sort(q+1,q+Q+1,cmp);
int last=0;
// for(int i=1;i<=Q;i++) cout<<q[i].d
for(int i=1;i<=Q;i++){
for(int k=last+1;k<=res;k++){
if(d[k].h<=q[i].day){
last=k;
break;
}
ans++;
int xx=d[k].x ,yy=d[k].y ;
cout<<d[k].id<<" "<<d[k].h <<endl;
// cout<<ans<<" "<<ton[k].id <<" "<<xx <<" "<<yy <<": "<<endl;
// memset(tag,0,sizeof(tag));
for(int j=1;j<=4;j++)
if(H[xx+fx[j]][yy+fy[j]]>=d[k].h){
cout<<xu[xx+fx[j]][yy+fy[j]]<<" "<<xx+fx[j]<<" "<<yy+fy[j]<<" ";
int now1=find(xu[xx+fx[j]][yy+fy[j]]),now2=find(d[k].id);
if(now1==now2) continue;
cout<<now1<<" "<<now2<<endl;
fa[now1]=now2;
ans--;
}
}
q[i].as=ans;
}
sort(q+1,q+Q+1,cmp2);
for(int i=1;i<=Q;i++) printf("%d
",q[i].as );
}
}
以上是关于2333的主要内容,如果未能解决你的问题,请参考以下文章