Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
跪求,why waint g[500][500],it[250000],jt[250000],lvl[250000]; int vet[5][2]={{0,1},{1,0},{-1,0},{0,-1},{0,0}}; void main(){ int t,i,k,a,b,top=1,low=0,f=0,ans=-1; scanf("%d",&t); memset(g,-1,sizeof(g)); while(t--){ scanf("%d%d%d",&a,&b,&k); for(i=0;i<5;i++)if(g[a+vet[i][0]][b+vet[i][1]]==-1||g[a+vet[i][0]][b+vet[i][1]]>k)g[a+vet[i][0]][b+vet[i][1]]=k; } if(g[0][0]==-1)ans=0; else while(top>low){ for(k=0;k<4;k++){ it[top]=it[low]+vet[k][0]; jt[top]=jt[low]+vet[k][1]; lvl[top]=lvl[low]+1; if(it[top]>=0&&jt[top]>=0){ if(g[it[top]][jt[top]]==-1){f=1;ans=lvl[top];break;} if(lvl[top]<g[it[top]][jt[top]])top++; } } low++; if(f)break; } printf("%d\n",ans); } wa了,写的很基础的广搜,不知有什么问题···· Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator