H - 【59】Lazier Salesgirl 模拟//lxm
Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy that she will fall asleep if no customer comes to buy bread for more than w minutes. When she is sleeping, the customer coming to buy bread will leave immediately. It's known that she starts to sell bread now and the i-th customer come after ti minutes. What is the minimum possible value of w that maximizes the average value of the bread sold?
Input
There are multiple test cases. The first line of input is an integer T ≈ 200 indicating the number of test cases.
The first line of each test case contains an integer 1 ≤ n ≤ 1000 indicating the number of customers. The second line contains n integers 1 ≤ pi ≤ 10000. The third line contains n integers 1 ≤ ti ≤ 100000. The customers are given in the non-decreasing order of ti.
Output
For each test cases, output w and the corresponding average value of sold bread, with six decimal digits.
Sample Input
2
4
1 2 3 4
1 3 6 10
4
4 3 2 1
1 3 6 10
Sample Output
4.000000 2.500000
1.000000 4.000000 题意是要求出时间w使得卖出面包的平均价格最大
这个题可以求出到第i个客服保持清醒的时间w[i]然后模拟一遍就可
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
#define maxn 1111
int p[maxn], times[maxn], w[maxn];
int t,n;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
for(int i=;i<n;i++)
cin>>p[i];
for(int i=;i<n;i++)
cin>>times[i];
w[]=times[];
for(int i=;i<n;i++)
w[i]=max(times[i]-times[i-],w[i-]);//到第i个所需要的最大的时间
double the_time=,sum,ave,time;
ave=;
for(int i=;i<n;i++)
{
time=w[i];
sum=;
int cnt=;
for(int j=;j<n;j++)
{
if(time>=w[j])
{
sum+=p[j];
cnt++;
}
else
break;
}
if(ave<sum/cnt)
{
ave=sum/cnt;
the_time=time;
}
else if (ave==sum/cnt)
{
the_time=min(the_time,time);
}
}
printf("%.6lf %.6lf\n",the_time,ave);
}
return ;
}
H - 【59】Lazier Salesgirl 模拟//lxm的更多相关文章
- ZOJ 3607 Lazier Salesgirl (枚举)
Lazier Salesgirl Time Limit: 2 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes ...
- zjuoj 3607 Lazier Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 Lazier Salesgirl Time Limit: 2 Sec ...
- H - Lazier Salesgirl
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...
- [ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]
Description Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making ...
- H.数7(模拟)
1212: H.数7 时间限制: 1 Sec 内存限制: 64 MB 提交: 8 解决: 5 标签提交统计讨论版 题目描述 数7是一个简单的饭桌游戏,有很多人围成一桌,先从任意一人开始数数,1.2 ...
- ZOJ 3607 Lazier Salesgirl 贪心
这个题比上个题简单得多,也是超过W时间会睡着,睡着就再也不会卖了,顾客按时间顺序来的,但是可能有顾客同时到(同时到如果醒着就全卖了),并且每个人只买一块面包,也是求最大的W,使得卖出面包的平均价格最高 ...
- ZOJ 3607 Lazier Salesgirl
Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling ...
- CERC2017 H Hidden Hierarchy(树+模拟)
题意: 在一些给定的目录里按要求展开到制定大小并按字典序输出 思路: 因为有目录这个东西,所以想到模拟一个类似字典树的东西,不过这里每个儿子可能有n个节点,而且不能O(1)查询了 代码超长.. #in ...
- ZOJ 3607 Lazier Salesgirl(贪心)
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...
随机推荐
- MySql 插入数据返回数据的Id值
insert into addeditemgroup(addeditemgroupname) value(') ; select @@IDENTITY as id; 返回最新的Id:
- MVC ---- IEnumerable<T>、List<T> 前台遍历展示
突然做前台数据展示,发现IEnumerable 对一个列表的展示还是可以,但要是多个类型放在一个表中如何处理呢,如下: 一个类IEnumerable遍历 后台 public IEnumerable&l ...
- MVC ---- 如何使用Predicate以及如何自定定义Predicate委托
微软公司提供只能返回bool值,接受一个参数的委托类型(Predicate). //Predicate委托 public static class PredicateDemo{ //内置方法 publ ...
- c++ 判断两个容器是否相等(equal)
#include <iostream> // cout #include <algorithm> // equal #include <vector> // vec ...
- JSONObject获取的值有时候不是String类型,而有时候又是String类型,怎么办呐
{ "weatherinfo": { "city": "深圳", "cityid": "101280601&q ...
- cqlsh 一个错误
C:\Users\jasqia>cqlsh 10.215.70.158 1433Can't detect Python version! http://zqhxuyuan.github.io/2 ...
- Asp.net Ajax(ashx)
主要实现 ajax分页功能 效果图 后台方法代码展示 /// <summary> /// WebAjax处理类 /// </summary> public class WebA ...
- Python day21模块介绍4(logging模块,configparser模块)
1.日志等级从上往下依次降低 logging.basicConfig(#日志报错打印的基础配置 level=logging.DEBUG, filename="logger.log" ...
- BN层
论文名字:Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift 论 ...
- 【Golang】 可以自动生成测试用例的库--gotests
简介 gotests是一个Golang命令行工具,它可以使编写Go的测试代码变得容易.它能基于目标源文件的函数和方法生成数据驱动测试用例,并且在此过程会自动导入任何依赖. 下面是gotests在使用S ...