POJ 1042 Gone Fishing(模拟+贪心)
来源:互联网 发布:廊坊市网络招聘 编辑:程序博客网 时间:2024/05/21 10:39
题目地址:http://poj.org/problem?id=1042
思路:模拟+贪心
AC代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct node{ int first; int reduce;}a[30];int b[30];int time[30];int pre[30][30];int c[30];int main(){ int n,h; while(scanf("%d",&n) && n) { scanf("%d",&h); h *= 12; memset(pre,0,sizeof(pre)); memset(c,0,sizeof(c)); for(int i=1; i<=n; i++) scanf("%d",&a[i].first); for(int i=1; i<=n; i++) scanf("%d",&a[i].reduce); time[1] = 0; for(int i=2; i<=n; i++) { int x; scanf("%d",&x); time[i] = time[i-1] + x; } for(int i=1; i<=n; i++) { int total = h - time[i]; for(int j=1; j<=i; j++) b[j] = a[j].first; for(int j=1; j<=total; j++) { int max1 = b[1]; int tt = 1; for(int k=1; k<=i; k++) { if(b[k] > max1) { max1 = b[k]; tt = k; } } b[tt] -= a[tt].reduce; if(b[tt] < 0) b[tt] = 0; c[i] += max1; pre[i][tt]++; } } int max1 = -1; int l; for(int i=1; i<=n; i++) { if(c[i] > max1) { max1 = c[i]; l = i; } } for(int i=1; i<=n-1; i++) printf("%d, ",pre[l][i]*5); printf("%d\n",pre[l][n]*5); printf("Number of fish expected: %d\n\n",max1); } return 0;}
0 0
- POJ 1042 Gone Fishing(模拟+贪心)
- poj 1042 Gone Fishing(贪心 钓鱼)
- POJ 1042 Gone Fishing(贪心+枚举)
- POJ 1042 Gone fishing(枚举+贪心)
- POJ 1042 Gone Fishing (贪心)
- POJ 1042 Gone Fishing(贪心)
- poj 1042 Gone Fishing(贪心)
- POJ 1042:Gone Fishing【贪心】
- poj 1042 Gone Fishing(贪心)
- POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)
- POJ - 1042 Gone Fishing(钓鱼)(深搜+贪心)
- NYOJ 30 && POJ 1042 Gone Fishing(枚举+贪心)
- poj 1042 gone fishing 贪心+枚举
- POJ 1042 Gone Fishing(贪心+枚举)
- POJ-1042-Gone Fishing-枚举+贪心
- POJ 1042 Gone Fishing 贪心 枚举
- poj 1042 Gone Fishing 枚举+贪心
- Poj-1042-Gone Fishing-枚举+贪心
- OpenCV:对XML和YAML文件实现I/O操作
- 页面布局之双飞翼布局
- 使用引用形参返回额外信息
- c++作业4
- C++上级实验4-求1000以内所有偶数的和
- POJ 1042 Gone Fishing(模拟+贪心)
- 深拷贝与浅拷贝
- Leetcode 1, Two Sum
- swift - NSUserDefaults 的使用
- 【排序算法】选择排序原理及Java实现
- postDelayed方法和removeCallbacks方法的使用
- leetcode——230——Kth Smallest Element in a BST
- OpenCV : InputArray和OutputArray
- 官网 Icinga Version 1.9 Documentation