您的位置:首页 > 其它

[ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]

2014-03-16 16:20 429 查看
Description

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

题目大意:T种情况,每种n个客人,第i个客人可赚p[i]元钱,第i个客人t[i]时间来,卖东西的很懒,如果w时间内没人来就睡觉,一觉不起,求最大人均赚的钱同时输出最小w.
解题思路:暴力枚举每次在第i个顾客来后睡。用w[i]保存想赚第i个人w的最小值,用av[i]保存赚前i个顾客的平均值。如果在第i个顾客来后睡觉就要满足w[i]<w[i+1](这个式子表明第i和第i+1个顾客之间的时间间隔比之前的都大,所以可以取w=w[i]来在这点后睡觉不醒)


#include<iostream>
#include<string.h>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
int main(){
int T;cin>>T;
while(T--){
int n;cin>>n;
int p[1002],t[1002];
//w[i]表示赚第i个人需要w的最小值;av[i]表示前i个的人均赚钱数
double w[1002],av[1002];
double sum=0;
for(int i=0;i<n;i++){
cin>>p[i];
sum+=p[i];
av[i]=sum/(i+1);
}
double max_w=-1;
for(int i=0;i<n;i++){
cin>>t[i];
if(i!=0){
if(t[i]-t[i-1]>max_w){
max_w=t[i]-t[i-1];
w[i]=max_w;
}else w[i]=max_w;
}
else {
max_w=t[0];
w[i]=max_w;
}
}w
=1312312313;//w
赋值很高

int pos=0;double max_av=-1;//暴力枚举在i点睡着
for(int i=0;i<=n;i++){
if(w[i]<w[i+1]){
if(av[i]>max_av){
max_av=av[i];
pos=i;
}
}
}

printf("%.6lf %.6lf\n",w[pos],av[pos]);
}return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: