uva-757-贪心
题意:有个人要去湖里钓鱼,总共有N个湖,排成一个序列,用字母P表示湖,从湖pi 到 pi+1(下一个湖)需要ti个五分钟.
并且,每个湖里可钓出来的鱼每过五分钟就减少di.如果产出的鱼小于等于di.那么下个五分钟这个湖再也不会产出鱼.
问:使得总的钓出鱼数目最大和每个湖花费的对应时间,.如果鱼数目最大存在多种解,让时间尽可能花费在前面的湖上.
解法:
枚举每一个pi,划去从p0至pi的总time(总的转移时间).
这样我们就可以在任意p0-pi之间钓鱼而不用考虑time的问题.剩下的h全部花费在钓鱼上.
每次花费的五分钟都花在产出鱼数目最大的湖上.这样得到总鱼数目总是最大的.如果所有的鱼都钓完还有时间剩余.全部加在第一个湖上面.
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
#include<math.h>
#include<iomanip>
#include<bitset>
#include"math.h"
namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string;
using std::sort;
using std::priority_queue;
using std::greater;
using std::vector;
using std::swap;
using std::stack;
using std::queue;
using std::bitset; class State
{
public: int curFish;
int d;
int time;
int index;
State() {}
State(int curFish, int d, int time, int index) :
curFish(curFish), d(d), time(time), index(index)
{ }
friend bool operator < (const State& s1, const State& s2)
{
if (s1.curFish != s2.curFish)
return s1.curFish < s2.curFish;
return s1.index > s2.index;
}
}; constexpr int N = ;
int H = ;
int n; int totalFish;
int per[N] = { };
State states[N]; priority_queue < State>q; void solve()
{
int t = ;
while (cin >> n && n)
{
if (t != )
cout << endl;
++t;
cin >> H;
H = H * ;
int f = ;
for (int i = ;i < n;i++)
{
cin >> f;
State state(f, , , i);
states[i] = state;
}
for (int i = ;i < n;i++)
{
cin >> states[i].d;
}
for (int i = ;i < n;i++)
{
cin >> states[i].time;
states[i].time = states[i].time + states[i-].time;
}
totalFish = -;
memset(per, , sizeof(per));
for (int i = ;i < n;i++)
{
while (q.empty() == false)
q.pop();
for (int k = ;k <= i;k++)
q.push(states[k]);
int h = H;
int curTotalFish = ;
int times[N] = {};
h = h - states[i].time;
while (h > )
{
State s = q.top();
q.pop();
int f = s.curFish;
if (f <= )break;
--h;
s.curFish -= s.d;
curTotalFish += f;
times[s.index]++;
q.push(s);
}
if (h > )
times[] += h;
if (curTotalFish > totalFish)
{
totalFish = curTotalFish;
memcpy(per, times, sizeof(times));
}
}
cout << per[] * ;
for (int i=;i<n;i++)
cout<<", " << per[i] * ;
cout << endl;
cout << "Number of fish expected: " << totalFish << endl;
}
}
}; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return ;
}
uva-757-贪心的更多相关文章
- 01_传说中的车(Fabled Rooks UVa 11134 贪心问题)
问题来源:刘汝佳<算法竞赛入门经典--训练指南> P81: 问题描述:你的任务是在n*n(1<=n<=5000)的棋盘上放n辆车,使得任意两辆车不相互攻击,且第i辆车在一个给定 ...
- UVA 11389(贪心问题)
UVA 11389 Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Description II ...
- uva 10154 贪心+dp
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- uva 757
贪心 优先队列 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...
- UVa 11389 (贪心) The Bus Driver Problem
题意: 有司机,下午路线,晚上路线各n个.给每个司机恰好分配一个下午路线和晚上路线. 给出行驶每条路线的时间,如果司机开车时间超过d,则要付加班费d×r. 问如何分配路线才能使加班费最少. 分析: 感 ...
- UVa 1467 (贪心+暴力) Installations
题意: 一共有n项服务,每项服务有安装的时间s和截止时间d.对于每项任务,如果有一项超出截止时间,惩罚值为所超出时间的长度.问如何安装才能使惩罚值最大的两个任务的惩罚值之和最小. 分析: 如果是求总惩 ...
- UVa 757 - Gone Fishing
题目大意:John有h的时间可以去钓鱼,有n湖可钓鱼,以5分钟为时间单位,每个湖初始每个单位时间可钓f条鱼,每下一个时间单位数量减少d条.同时,John只能从1号湖往后走进行钓鱼,湖之间的距离需要t个 ...
- Party Games UVA - 1610 贪心
题目:题目链接 思路:排序后处理到第一个不同的字符,贪心一下就可以了 AC代码: #include <iostream> #include <cstdio> #include ...
- UVa 1149 (贪心) Bin Packing
首先对物品按重量从小到大排序排序. 因为每个背包最多装两个物品,所以直觉上是最轻的和最重的放一起最节省空间. 考虑最轻的物品i和最重的物品j,如果ij可以放在一个包里那就放在一起. 否则的话,j只能自 ...
- UVA 10037 贪心算法
题目链接:http://acm.hust.edu.cn/vjudge/contest/122829#problem/A 题目大意:N个人夜里过河,总共只有一盏灯,每次最多过两个人,然后需要有人将灯送回 ...
随机推荐
- JS之clientX,clientY,screenX,screenY,offsetX,offsetY区别
首先需要知道clientX,clientY,screenX,screenY,offsetX,offsetY 是鼠标事件对象下的几个属性. 之前也一直对这些属性搞的稀里糊涂,看文档上说的也是不太理解,反 ...
- 解题报告 『机器翻译(vector)』
原题地址 本想练习一下模拟,不过用vector貌似可以轻松水过?(虽然还是模拟) 但突然发现貌似我并不会判断单词是否在内存中出现过? 最后还是靠度娘解决了. 代码如下: #include <bi ...
- poj 1039
#include <iostream> #include <algorithm> #include <cstring> #include <cstdlib&g ...
- Development descriptor
部署描述符指的是配置文件对于一个假象部署到一些容器/发动机. 在Java平台,企业版部署描述符描述组件.模块或应用程序(例如web应用程序或者企业应用程序)应该被部署.它指导部署工具部署具有特定容器选 ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 从零开始在iPhone上运行视频流实时预测模型应用,只需10步
1、买一台苹果电脑,建议MacBook Pro. 2、安装Xcode. 3、克隆TensorFlow:https://github.com/tensorflow/tensorflow.git 4、下载 ...
- java8_api_格式化数据
格式化数据1 Locale类 格式化日期时间 格式化数字 Locale类,主要是国际化相关 该类代表语言环境 实例化: ...
- 关于FIFO异步复位的问题
关于FIFO异步复位的问题 FIFO异步复位的宽度,需要保证至少3个较慢时钟的时钟周期长度. 怎样对一个脉冲加宽呢? `timescale 1ns / 1ps //////////////////// ...
- Unity 中实现粒子系统的 LOD
模型的 LOD 比较简单,直接使用 Unity 提供的组件 LODGroup 挂到模型物体上,然后分别指定不同 LOD 级别的 Renderer 即可. LODGroup 并不是用距离来控制 LOD, ...
- bpmn-js起步
https://blog.csdn.net/u013253924/article/details/85784002 通过本文逐步熟悉bpmn-js. 快速介绍: bpmn.js是一个BPMN2.0渲染 ...