[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];elsebreak;}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
[ZOJ 3607] Lazier Salesgirl相关推荐
- ZOJ 2723 Semi-Prime ||ZOJ 2060 Fibonacci Again 水水水!
两题水题: 1.如果一个数能被分解为两个素数的乘积,则称为Semi-Prime,给你一个数,让你判断是不是Semi-Prime数. 2.定义F(0) = 7, F(1) = 11, F(n) = F( ...
- zoj 1204 Additive equations
ACCEPT acm作业 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=204 因为老师是在集合那里要我们做这道题.所以我很是天 ...
- 【HDU/POJ/ZOJ】Calling Extraterrestrial Intelligence Again (素数打表模板)
http://poj.org/problem?id=1411 POJ http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=168 ...
- 模拟 ZOJ 3878 Convert QWERTY to Dvorak
题目传送门 1 /* 2 模拟:手敲map一一映射,累! 3 除了忘记读入字符串不能用gets用getline外还是很顺利的AC了:) 4 */ 5 #include <cstdio> 6 ...
- 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence
题目传送门 1 /* 2 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 3 矩阵连乘积问题,DP解决:状态转移方程: 4 dp[i][j] = min (dp[i][k] + dp[k+1] ...
- ZOJ 3597 Hit the Target! (线段树扫描线 -- 矩形所能覆盖的最多的点数)
ZOJ 3597 题意是说有n把枪,有m个靶子,每把枪只有一发子弹(也就是说一把枪最多只能打一个靶子), 告诉你第 i 把枪可以打到第j个靶, 现在等概率的出现一个连续的P把枪,在知道这P把枪之后,你 ...
- 九度OJ—题目1032:ZOJ
题目描写叙述: 读入一个字符串.字符串中包括ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出.当某个字符用完时,剩下的仍然依照ZOJ的顺序输出. 输入: 题目包括多组用例,每组用例占一行,包括ZOJ ...
- ZOJ 1410 题解
题目链接:http://acm.zju.edu.cn/show_problem.php?pid=1410 又是一道简单题,以前做过一次,结果放弃了,今天看了一下,觉得还是比较简单于是下手了. 题目的大 ...
- POJ 1201 amp; HDU1384 amp; ZOJ 1508 Intervals(差分约束+spfa 求最长路径)
题目链接: POJ:http://poj.org/problem?id=1201 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1384 ZOJ:htt ...
- poj 1436 zoj 1391 Horizontally Visible Segments (Segment Tree)
ZOJ :: Problems :: Show Problem 1436 -- Horizontally Visible Segments 用线段树记录表面能被看见的线段的编号,然后覆盖的时候同时把能 ...
最新文章
- 不同的设计模式的特点总结
- MyEclipse Enterprise Workbench 9.0 破解及注册机 注册码
- kubernetes组件
- 日常办公会用到的python模块-用 Python 自动化办公能做到哪些有趣或有用的事情?...
- armadillo 使用注意 越界不报错
- 云有约 | 在去O的道路上,AWS表示:经验可复制,惊喜并非只属于我们!
- 日语输入法 android8.0,讯飞输入法发布 AndroidV8.0.6855 专注提升输入效率
- 给网站加上“新年快乐”灯笼源码
- 机器学习基础 | 有监督学习篇
- 消息队列实现socket 消息同步_消息队列二三事
- 哔哩哔哩电脑版怎么下载视频?
- 六年如逆旅,我亦是行人:一个顾问的六年安全从业经历
- Windows 检测PPT WPS 幻灯片播放并获取窗口句柄
- CCIE一年后的心语
- 年度催泪之作:2015中国程序员生存报告
- 开源资产扫描系统-ARL资产灯塔系统
- Android 和 H5 交互-框架篇
- openwrt开启网络共享Samba
- 两子公司犯单位行贿罪各罚100万 鹏博士收警示函高度重视
- SpringBoot究竟是如何跑起来的?