POJ 1928 The Peanuts
来源:互联网 发布:话费充值 聚合数据 编辑:程序博客网 时间:2024/04/30 11:55
这两天的作业题目都没有什么技术含量,这道题只需要把每个有花生的点按照花生的量从大到小排起来,然后从头开始一个一个找,如果能摘到花生并且安全走到公路上就把花生加到我们的总数上。注意每次判断能不能走到某个点的时候要把走回到公路的时间也算上,判断完之后要注意在把走到公路所用的时间减去。
总之没什么技术含量……简单粗暴
#include<iostream>#include<cmath>#include<cstdio>#include<memory.h>#include<algorithm>using namespace std;#define maxn 55struct peanuts{ int x,y; int num;};bool operator < (peanuts a, peanuts b){ return a.num > b.num;}int m,n,time_units;int map[maxn][maxn]={0};peanuts peanut[maxn*maxn]={0};int pcount = 0;void init(){ memset(peanut,0,sizeof(peanut)); memset(map,0,sizeof(map)); pcount = 0; scanf("%d%d%d",&m,&n,&time_units); for(int i=0;i<m;++i){ for(int j=0;j<n;++j){ scanf("%d",&map[i][j]); if(map[i][j]){ peanut[pcount].x = i; peanut[pcount].y = j; peanut[pcount].num = map[i][j]; pcount++; } } } sort(peanut,peanut+pcount);}int work(){ int result = 0; int steps = 1; steps += peanut[0].x + 1; steps += peanut[0].x + 1; if(steps > time_units) return 0; result += peanut[0].num; //printf("%d\n",result); steps -= peanut[0].x + 1; for(int i=1;i<pcount;++i){ int dis = 0; dis += abs(peanut[i].x - peanut[i-1].x); dis += abs(peanut[i].y - peanut[i-1].y); steps += dis + 1; steps += peanut[i].x + 1; if(steps > time_units) return result; steps -= peanut[i].x + 1; result += peanut[i].num; } return result;}int main(){ int t; scanf("%d",&t); while(t--){ init(); printf("%d\n",work()); } //system("pause"); return 0; }
0 0
- poj 1928 The Peanuts
- POJ-1928-The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts 笔记
- ACM篇:POJ 1928--The Peanuts
- poj 1928 peanuts 排序
- pku 1928 The Peanuts
- POJ:1928 花生问题 The Peanuts
- fjnu 1013 The Peanuts
- hdu 1355 The Peanuts
- hdu1355 The Peanuts
- POJ1928 The Peanuts
- POJ1928 The Peanuts
- ZOJ2235 POJ1928 HDU1355 The Peanuts
- hdu 1355 The Peanuts(DP)
- HDOJ 1355 The Peanuts(水)
- MySQL 入门
- 数据结构(三)
- 学netstore案例的感想
- c++ core Guidelines 翻译+读书笔记
- iOS 7应用开发公开课笔记 L3:Objective-C
- POJ 1928 The Peanuts
- App Store Review Guidelines中文版
- IOException : DerInputStream.getLength(): lengthTag=26, too big.
- 31-linux登录mysql
- Spring JMS 使用
- mysql数据类型
- 自定义tabbar的步骤
- Two Strings Are Anagrams
- 1095. Cars on Campus (30)