ZOJ 3607 Lazier Salesgirl (枚举)
Lazier Salesgirl
Time Limit: 2 Seconds Memory Limit: 65536 KB
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
枚举
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
int n;
int p[1005];
int t[1005];
int w;
int main()
{
int t1;
scanf("%d",&t1);
while(t1--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&p[i]);
int num1=0;
int num2=100000;
t[0]=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&t[i]);
num1=max(num1,t[i]-t[i-1]);
num2=min(num2,t[i]-t[i-1]);
}
int pos=1;
double res=0;
double ans;
for(w=num2;w<=num1;w++)
{
int sum=0;int num=0;
int time=w;
for(int i=1;i<=n;i++)
{
if(t[i]<=time)
{
sum+=p[i];
num++;
time=t[i]+w;
}
else
{
break;
}
}
double av=1.0*sum/num;
if(res<av)
{
res=av;
ans=w;
}
}
printf("%.6f %.6f\n",ans,res);
}
return 0;
}
ZOJ 3607 Lazier Salesgirl (枚举)的更多相关文章
- ZOJ 3607 Lazier Salesgirl(贪心)
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...
- 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 ...
- 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 ...
- ZOJ 3607贪心算法
http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...
- [ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]
Description Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making ...
- ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛
Lazy Salesgirl Time Limit: 5 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...
- 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 ...
随机推荐
- struts2设置加载非默认路径的struts.xml文件解决方案
方案一: 首先我们要明白struts2加载配置文件都是从它自己的jar包和\WEB-INF\classes两个默认的位置加载的,如果你想改变strusts2中的文件的默认加载路径,可以在web项目 ...
- 集合运算 蓝桥杯 set容器
题目描述 给出两个整数集合A.B,求出他们的交集.并集以及B在A中的余集. 输入格式 第一行为一个整数n,表示集合A中的元素个数. 第二行有n个互不相同的用空格隔开的整数,表示集合A中的元素. 第三行 ...
- 实例37foreach遍历数组
package test; import java.util.List; import java.util.ArrayList; import java.util.Scanner; /** * @au ...
- 一份不错的php面试题(附答案)(笔试题)
一.基础题1. 写出如下程序的输出结果 <?php $str1 = null; $str2 = false; echo $str1==$str2 ? '相等' : '不相等'; $str3 = ...
- 基于vitamio的网络电视直播源代码
这个项目是基于vitamio的网络电视直播源代码.也是一个使用了vitamio的基于安卓的网络直播项目源代码,可能如今网上已经有非常多类似这种视频播放应用了.只是这个还是相对来说比較完整的,希望这个案 ...
- [gpio]Linux GPIO简单使用方式2-sysfs
转自:http://blog.csdn.net/cjyusha/article/details/50418862 在Linux嵌入式设备开发中,对GPIO的操作是最常用的,在一般的情况下,一般都有对应 ...
- 实现ping程序
//ping.h头文件如下所示: #define ICMP_ECHOREPLY 0 /*ECHO应答*/ #define ICMP_ECHO 8 /*ECHO请求*/ #define BUFSIZE ...
- ReentrantReadWriteLock读写锁的使用<转>
Lock比传统线程模型中的synchronized方式更加面向对象,与生活中的锁类似,锁本身也应该是一个对象.两个线程执行的代码片段要实现同步互斥的效果,它们必须用同一个Lock对象. 读写锁:分为读 ...
- Android——UI和View——控制方式
控制方式 只用xml实现 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns ...
- C++ 类中的静态成员变量,静态成员函数
//类中的静态成员变量,静态成员函数 #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; /* ...