hdu 1355 The Peanuts
来源:互联网 发布:c语言入门书籍 pdf 编辑:程序博客网 时间:2024/04/30 15:50
题目链接..
/*********************************
看清题目,直接模拟,题中已经说了怎么做了:According to Mr. Robinson's requirement, Dodo should go to the plant with the most peanuts first. After picking them, he should then go to the next plant with the most peanuts, and so on.
从多到少开始摘。
*******************************/
#include"stdio.h"#include"math.h"#include"stdlib.h"int map[51][51],n,m,k;struct node{ int x,y,count;}aa[2502];int cmp(const void*a,const void*b){ return (*(struct node*)b).count-(*(struct node*)a).count;}int main(){ int t,i,j,l,a,T,xx,yy,temp,ans;; scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&k); l=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%d",&map[i][j]); if(map[i][j]!=0) { aa[l].x=i; aa[l].y=j; aa[l++].count=map[i][j]; } } } qsort(aa,l,sizeof(aa[0]),cmp); t=0;ans=0; xx=0; yy=aa[0].y; for(i=0;i<l;i++) { temp=fabs(aa[i].x-xx)+fabs(aa[i].y-yy); if(t+temp+aa[i].x+1<=k) { t=t+temp+1; xx=aa[i].x; yy=aa[i].y; ans+=aa[i].count; } else break; } printf("%d\n",ans); } return 0;}
- hdu 1355 The Peanuts
- hdu 1355 The Peanuts(DP)
- HDU 1355 The Peanuts
- HDOJ 1355 The Peanuts(水)
- 杭电OJ 1355:The Peanuts
- fjnu 1013 The Peanuts
- pku 1928 The Peanuts
- poj 1928 The Peanuts
- hdu1355 The Peanuts
- POJ-1928-The Peanuts
- POJ1928 The Peanuts
- POJ1928 The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- ZOJ2235 POJ1928 HDU1355 The Peanuts
- POJ 1928 The Peanuts 笔记
- The Peanuts--很水的模拟题~~
- Hibernate配置文件和映射元素解释
- Android中ListView动态添加删除项
- HDU 4308 - Saving Princess claire_
- 等离子体
- PhysX学习记录 八 Spherical Joint
- hdu 1355 The Peanuts
- DataGridView 中Combobox 重载事件
- 挺喜欢的一张图片
- 也说9158手机视频
- VC++6.0连接ACCESS2007中的一个问题(ConnectionPtr, CreateInstance, CoInitialize(NULL))
- BNU 12886 - gabrielus
- 软件测试用例
- Android Training - 建立你的第一个应用程序
- C++Simplify02-基础语法