ZOJ 3607 Lazier Salesgirl 贪心
这个题比上个题简单得多,也是超过W时间会睡着,睡着就再也不会卖了,
顾客按时间顺序来的,但是可能有顾客同时到(同时到如果醒着就全卖了),
并且每个人只买一块面包,也是求最大的W,使得卖出面包的平均价格最高。
同理最大的W一定是某两个相邻人的时间差。因为睡着了就不会醒了,
所以枚举的时间差必须越来越大。如果某个时间差比前面枚举过的小也没啥意义
(因为在前面就会睡着)。因此,直接枚举第i个人和第(i-1)个人的那个时间差
(在此之前的时间差都比这个小),然后从第(i+1)个人开始连续一段人的时间差都不超过这个值,
直到第j个人的时间差比这个大,则从第一个人到第j个人都没睡着卖出去了,算一个均值。
再从第j个人的时间差开始判断,相当于扫了一遍。时间复杂度O(n)。 类似这样:
for (i=1;i<=n;i=j) {
for (d=t[i]-t[i-1],j=i;t[j]-t[j-1]<=d;++j) { 累加和不清0}
}
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int N = ;
const int M = * ;
const ll P = 10000000097ll ;
const int MAXN = ;
const int INF = 0x3f3f3f3f ; int n;
double t[], p[], lev[];
double sum, ans, anst, w; int main() {
std::ios::sync_with_stdio(false);
int i, j, T, k, u, v, numCase = ;
cin >> T;
while (T--){
sum = ans = anst = ;
cin >> n;
for (i = ; i < n; ++i) cin >> p[i];
for (i = ; i < n; ++i) cin >> t[i];
lev[] = t[];
for (i = ; i < n; ++i){
lev[i] = Max(t[i] - t[i - ], lev[i - ]);//找到相邻两人间的时间差
}
for (i = ; i < n; ++i){
w = lev[i];
sum = ;
for (j = ; j < n; ++j){
if (w >= lev[j]){
sum += p[j];
}
else break;
}
if (ans < sum / j){
ans = sum / j;
anst = w;
} else if (ans == sum / j && anst > w){
anst = w;
}
}
printf("%.6f %.6f\n", anst, ans);
} return ;
}
ZOJ 3607 Lazier Salesgirl 贪心的更多相关文章
- ZOJ 3607 Lazier Salesgirl (枚举)
Lazier Salesgirl Time Limit: 2 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes ...
- ZOJ 3607 Lazier Salesgirl(贪心)
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...
- ZOJ 3607 Lazier Salesgirl
Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling ...
- zjuoj 3607 Lazier Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 Lazier Salesgirl Time Limit: 2 Sec ...
- ZOJ 3607贪心算法
http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...
- H - Lazier Salesgirl
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...
- ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛
Lazy Salesgirl Time Limit: 5 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...
- POJ 1862 & ZOJ 1543 Stripies(贪心 | 优先队列)
题目链接: PKU:http://poj.org/problem?id=1862 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- 2017CCPC秦皇岛G ZOJ 3987Numbers(大数+贪心)
Numbers Time Limit: 2 Seconds Memory Limit: 65536 KB DreamGrid has a nonnegative integer n . He ...
随机推荐
- Cubieboard 关闭板载led
修改script.bin 找到最后节点[led_para] 修改leds_used = 0 script.bin 一般在系统盘的第一个分区 例如nand就在/dev/nanda sdcard就在/d ...
- 磁盘IO子系统学习资料
1.http://www.ibm.com/developerworks/cn/linux/l-cn-read/ (IBM read系统调用剖析) 2.http://lenky.info/arch ...
- 帝国cms7.0,列表模板调用不支持附表字段
帝国cms在制作列表模板时,是不支持一些字段的调用的,原因是因为有些字段所在的位置为附表,本段详细向你介绍 帝国如何调用副表字段 我们可在 系统---管理数据表---管理字段中查看 如果我们需要调用附 ...
- 灵动标签内sql语句调用
本节来介绍帝国cms中,灵动标签中如何写数据库调用我们所要的信息.方便一些没有学习过数据库的朋友 转载请注明出处:谢寒的博客 灵动标签默认的语法 [e:loop={栏目ID/专题ID,显示条数,操作类 ...
- Hbuilder 常用快捷键汇总
朋友推荐用Hbuilder编辑器,看了下Hbuilder官网和那视频,感觉牛逼哄哄的, 自己也就体验了一下,打开Hbuilder的快捷键列表,每个快捷键都体验了一下,以下展示出来的,每一个都是精华,每 ...
- poj 2155
题目链接 二维树状数组 给出矩阵左上角和右下角坐标,矩阵里的元素 1变0 ,0 变1,然后给出询问,问某个点是多少. 树状数组下标不能为0 二维的每次更新都是从(1,1)到(x,y) 要更新(x1,y ...
- c#个性化安装包
近来想做一个模仿QQ或猎豹浏览器那样的个性化安装包,NSIS或IS等简单看了一下,比较复杂还不确定能不能实现. 想了一下,可以自己开发一个安装包程序,新建一个windows项目,但不知如何将已开发完成 ...
- ThinkPHP第九天(在Admin分组中配置__PUBLIC__,$POST异步传输,import使用方法,验证码点击刷新方法,Create方法作用)
1.项目分组之后,后台模板的公用文件一般放置在Tpl/Admin/Public中,这样子在替换模板路径时候如果还用__PUBLIC__时为了不与前台冲突,应该在Admin/config.php中配置一 ...
- __call重载方法
<?php class Person { function du() { echo "这是一个存在的方法"; } //该方法有两个参数,第一个参数 $function_nam ...
- 转: cmd和amd的区别
AMD 规范在这里:https://github.com/amdjs/amdjs-api/wiki/AMDCMD 规范在这里:https://github.com/seajs/seajs/issues ...