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 |
1928没头没脑就AC了题目的要求很简单, 每次寻找最多花生的点摘取, 每个点都不会有相同数目的花生, 看见那么多人过了,我没头没脑地想,48Ms一次AC了。 #include <iostream> #include <algorithm> #include <cmath> using namespace std; int tian[50][50],a,b; void findout(int shu,int&x,int&y) { for (x=0;x<a;x++) { for (y=0;y<b;y++) if (tian[x][y]==shu) break; if (y!=b) break; } }//寻找某个数目花生对应的横纵座标 int main() { int n,i,j,k,zhiyin[2500],x,y,*p,guozi,route,x1,y1; cin>>n; while (n--) { cin>>a>>b>>k; for (i=0;i<a;i++) for (j=0;j<b;j++) { cin>>tian[i][j]; zhiyin[i*b+j]=tian[i][j]; } sort(zhiyin,zhiyin+a*b); p=zhiyin+a*b-1; findout(*p,y,x); if (k>2*(y+1)+1)//第一次取花生成功 { k-=y+2; guozi=*p; while(1) { if (p!=zhiyin) p--; else break; if (*p==0) break; findout(*p,y1,x1); route=abs(x-x1)+abs(y-y1)+1; if (k>=route+y1+1)//判断unit时加上回来的步数 { k-=route;//减的时候不用加上回来的步数 guozi+=*p; x=x1; y=y1; } else break; } cout<<guozi<<endl; } else if (k==(2*y+1)+1)//只能取到第一次花生 cout<<guozi<<endl; else cout<<'0'<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator