标签:des style blog http io color ar os sp
Description
Input
Output
Sample Input
2 6 7 21 0 0 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0 0 7 0 15 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0 6 7 20 0 0 0 0 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0 0 7 0 15 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 0 0 0 0
Sample Output
37 28
思路:先把花生个数从大到小排序,然后判断是否超时。
1 #include<stdio.h> 2 #include<math.h> 3 #include<stdlib.h> 4 5 struct point 6 { 7 int x; 8 int y; 9 int num; 10 }node[2510],temp; 11 12 int init(int m,int n) 13 { 14 int t,i,j,k=0; 15 for(i=1;i<=m;++i) 16 for(j=1;j<=n;++j) 17 { 18 scanf("%d",&t); 19 if(t) 20 { 21 node[k].x=j; 22 node[k].y=i; 23 node[k].num=t; 24 ++k; 25 } 26 } 27 return k; 28 } 29 30 int comp(const void *p1,const void *p2) 31 { 32 return (*(struct point *)p2).num-(*(struct point *)p1).num; 33 } 34 35 int main() 36 { 37 int T,m,n,i,time,k; 38 long sum; 39 scanf("%d",&T); 40 while(T--) 41 { 42 scanf("%d%d%d",&m,&n,&time); 43 sum=0; 44 k=init(m,n); 45 qsort(node,k,sizeof(struct point),comp); 46 time-=node[0].y; 47 for(i=0;i<k;++i) 48 { 49 if(time>=node[i].y+1) 50 { 51 sum+=node[i].num; 52 time-=abs(node[i].x-node[i+1].x)+abs(node[i].y-node[i+1].y)+1; 53 } 54 else 55 break; 56 } 57 printf("%d\n",sum); 58 } 59 return 0; 60 }
标签:des style blog http io color ar os sp
原文地址:http://www.cnblogs.com/wangrunwen/p/4081509.html