[ZOJ 3607] Lazier Salesgirl

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607

思路:最小的相隔时间肯定是两个时间的间隔,只需要计算每个时间间隔所获的价值的平均值,取最大的平均值以及其对应的时间间隔即可,注意,当平均值相等的时候,取时间间隔小的。
AC 代码:

#include <cstdio>
#include <vector>
#include <iostream>

using namespace std;

const int maxn = 1005;

int test;
int n;
int p[maxn];
int t[maxn];
vector<int> distime;

double solve(int dis_t)
{
    double ret = 0.0;
    int i;
    for(i = 1; i <= n; i++)
    {
        if(t[i]-t[i-1] <= dis_t)
            ret += p[i];
        else
            break;
    }
    return ret / (i-1);
}

int main()
{
    scanf("%d",&test);
    while(test--)
    {
        distime.clear();
        scanf("%d",&n);
        for(int i = 1; i <= n; i++)
            scanf("%d",&p[i]);
        t[0] = 0;
        for(int i = 1; i <= n; i++)
        {
            scanf("%d",&t[i]);
            distime.push_back(t[i] - t[i-1]);
        }
        double ave,ans_distime,ans_ave = -1.0;
        //for(vector<int>::iterator it = distime.begin();it != distime.end();it++)
        for(int i = 0; i < distime.size(); i++)
        {
            ave = solve(distime[i]);
            if(ave > ans_ave)
            {
                ans_distime = distime[i];
                ans_ave = ave;
            }
        }
        printf("%.6lf %.6lf\n",ans_distime,ans_ave);
    }
}

原文地址:https://www.cnblogs.com/youpeng/p/10805764.html

时间: 2024-11-08 08:06:55

[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 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

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

ZOJ 3607 Lazier Salesgirl(贪心啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4710 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 laz

zjuoj 3607 Lazier Salesgirl

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 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 th

H - Lazier Salesgirl

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3607 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 custome

ZOJ 3606 Lazy Salesgirl

题意: n(10^5)个客人来到商店  给出了来的时间和买东西的单价  售货员每隔w分钟会睡觉  如果客人来的时候她在睡觉就把她叫醒但是不买东西  买东西的客人的购买个数为1.2.3.1.2.3-循环  问  w为多大时  卖出的东西平均价格最高 思路: 容易想到将客人按来的时间排序  然后算出他们的间隔时间  w必为其中某个间隔时间  即枚举n个w的可能 如果我们将间隔排序  那么对于某个w  排在w前的所有人为买到东西的人  因此在枚举w的时候我们可以维护一个序列来不断的更新ans 假设已知

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

zoj 2156 - Charlie&#39;s Change

题目:钱数拼凑,面值为1,5,10,25,求组成n面值的最大钱币数. 分析:dp,01背包.需要进行二进制拆分,否则TLE,利用数组记录每种硬币的个数,方便更新. 写了一个 多重背包的 O(NV)反而没有拆分快.囧,最后利用了状态压缩优化 90ms: 把 1 cents 的最后处理,其他都除以5,状态就少了5倍了. 说明:貌似我的比大黄的快.(2011-09-26 12:49). #include <stdio.h> #include <stdlib.h> #include <

ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 最小生成树 Kruskal算法

题目链接:ZOJ 1718 POJ 2031 Building a Space Station 修建空间站 Building a Space Station Time Limit: 2 Seconds      Memory Limit: 65536 KB You are a member of the space station engineering team, and are assigned a task in the construction process of the statio