Noip2004P2 花生采摘
2011-09-07 23:01
169 查看
题目: | 花生采摘 | |
来源: | Noip2004P2 | |
题目大意: | M*N的矩阵中每个点有值,可进行k次操作,求依次去最大值最多能去多少。 每次操作为以下之一 1) 从路边跳到最靠近路边(即第一行)的某棵花生植株; 2) 从一棵植株跳到前后左右与之相邻的另一棵植株; 3) 采摘一棵植株下的花生; 4) 从最靠近路边(即第一行)的某棵花生植株跳回路边。 | |
数据范围: | 1 <= M, N <= 20、0 <= K <= 1000 | |
样例: | 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 | 37 |
做题思路: | 依照题意每次取最大知道剩下的操作数只够回到路边,记得啊这不是动规,还有采摘 也算操作。 | |
知识点: | 模拟、贪心 |
type act=record x,y,d:longint; end; var a:array[0..500]of act; n,m,i,j,ans,k,tot,x,y:longint; //================================================== procedure qsort(l,r:longint); var i,j,k:longint; t:act; begin i:=l;j:=r; k:=a[(l+r)shr 1].d; repeat whilea[i].d>k do inc(i); whilea[j].d<k do dec(j); ifi<=j then begin t:=a[i];a[i]:=a[j];a[j]:=t; inc(i);dec(j); end; untili>j; ifi<r then qsort(i,r); ifj>l then qsort(l,j); end; //================================================ begin readln(m,n,k); fori:=1 to m do begin forj:=1 to n do begin inc(tot); read(a[tot].d); a[tot].x:=i;a[tot].y:=j; end; readln; end; qsort(1,tot); i:=1; y:=a[1].y;x:=0; while(k>=0)and(i<=tot) do begin if(k-(abs(a[i].x-x)+abs(a[i].y-y))-a[i].x-1)>=0 then{<前往目标值距离和回到路边的距离和采摘操作总和是否在操作数内>} begin k:=k-(abs(a[i].x-x)+abs(a[i].y-y))-1;{<走过去并采摘>} x:=a[i].x;y:=a[i].y; inc(ans,a[i].d); end elsek:=0;{<不满足条件直接回路边>} inc(i); end; writeln(ans); end.题目来源:http://yuanti.tyvj.cn:8080/Problem_Show.asp?id=1043
相关文章推荐
- NOIP 2004 普及组 复赛 peanuts 花生采摘
- SDNU 1167.花生采摘【NOIP 2004 普及组】【贪心】【8月6】
- 1093 花生采摘 2004年NOIP全国联赛普及组【貌似贪心】
- noip普及组2004 花生采摘
- [普及] NOIP 2004 花生采摘
- [NOIP2004普及组]花生采摘
- NOIP2004普及组第2题 花生采摘
- noip2004 花生采摘 (枚举)
- 花生采摘
- 洛谷1086/NOI题库1.13.38/NOIP2004普及组第2题 花生采摘
- 【p1086-花生采摘】解题记录
- 洛谷 P1086 花生采摘
- 洛谷Oj-花生采摘-模拟
- 洛谷 P1086 花生采摘
- 花生采摘
- 洛谷1086 花生采摘 解题报告
- 花生采摘
- 花生采摘
- P1086 花生采摘
- 花生采摘