Codeforces Bayan 2012-2013 Elimination Round / 241A Old Peykan (贪心)

【题解】codeforces451E Devu and Flowers 容斥原理+组合计数 Description Devu wants to decorate his garden with flowers. He has purchased n boxes, where the i-th box contains fi flowers. All flowers in a single box are of the same color (hence they are indis... 阅读详情

A. Old Peykan
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kilometers long.

The Old Peykan travels 1 kilometer in 1 hour and consumes 1 liter of fuel during this time.

Each city ci (except for the last city cn) has a supply of si liters of fuel which immediately transfers to the Old Peykan if it passes the city or stays in it. This supply refreshes instantly k hours after it transfers. The Old Peykan can stay in a city for a while and fill its fuel tank many times.

Initially (at time zero) the Old Peykan is at city c1 and s1 liters of fuel is transferred to it's empty tank from c1's supply. The Old Peykan's fuel tank capacity is unlimited. Old Peykan can not continue its travel if its tank is emptied strictly between two cities.

Find the minimum time the Old Peykan needs to reach city cn.

Input

The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1.

The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1, s2, ..., sm (1 ≤ si ≤ 1000).

Output

In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.

Sample test(s)
input
4 6
1 2 5 2
2 3 3 4
output
10
input
2 3
5 6
5 5
output
14
Note

In the second sample above, the Old Peykan stays in c1 for 3 hours.


贪心思路:在s[i]最大的城市加最多的油,详见代码。


完整代码:

/*30ms,0KB*/

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int d[1001], s[1001];

int main(void)
{
	int m, k, count = 0, oil = 0, temp, maxn = 0;
	scanf("%d%d", &m, &k);
	for (int i = 0; i < m; ++i)
	{
		scanf("%d", &d[i]);
		count += d[i];
	}
	for (int i = 0; i < m; ++i)
		scanf("%d", &s[i]);
	for (int i = 0; i < m; ++i)
	{
		oil += s[i];
		maxn = max(maxn, s[i]);
		if (d[i] > oil)
		{
			temp = ceil((double)(d[i] - oil) / maxn);
			count += k * temp;
			oil += maxn * temp;
		}
		oil -= d[i];
	}
	printf("%d", count);
	return 0;
}



【CodeForces 214A】Old Peykan #include using namespace std; #define maxn 1010 #define Rep(i,s,t) for(int i = (s); i <= (t);i++) int m,k; int d[maxn],s[maxn]; int main(void) { scanf("%d%d",&m,&k); Rep(i,1,m)scanf("%d",&d[i]); 阅读详情

相关推荐

结构设计3D拆件与骨架模型构建实战:基于Creo 8.0的5个高效建模技巧

本文详细解析了基于Creo 8.0的结构设计3D拆件与骨架模型构建实战技巧,涵盖5个高效建模方法,包括参数化驱动、曲面分割、多实体协同设计等。通过骨架模型的智能应用,设计效率可提升30%以上,特别适合复杂产品的结构设计。文章还提供了TWS耳机充电仓等实战案例,帮助工程师快速掌握工业设计中的核心建模技术。

weixin_30000735的博客 571

Old Peykan--codeForces 241A--动态规划

Description There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan want

SCUT_Pein 742

告别模糊与偏色:使用RKISP Tuner为RK3588s+IMX415进行图像质量调优的实战心得

本文详细介绍了如何使用RKISP Tuner为RK3588s+IMX415进行图像质量调优的实战经验。从调试环境搭建到3A算法优化,再到画质增强模块的深度调参,提供了全面的技术指导和参数建议,帮助工程师解决噪声、色偏和细节模糊等常见问题,显著提升成像质量。

weixin_28729205的博客 452

[codeforces 241]A. Old Peykan

[codeforces 241]A. Old Peykan 试题描述 There arencities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right asc1, c2, ..., c...

weixin_30501857的博客 164

华为 MetaERP 财务模块的核心业务对象,按子模块与架构维度分类,以表格呈现,适配架构设计与实施落地

华为MetaERP财务模块基于4A架构(业务/应用/数据/技术)与TOGAF框架,实现业财一体化与全球合规。业务架构涵盖组织模型与核心流程,应用架构支撑财务操作,数据架构确保数据一致性,技术架构提供高性能技术底座。模块覆盖总账、应收应付、资产等子模块,支持多组织、多币种、多准则核算,通过实时会计引擎实现"交易即核算"。4A架构与TOGAF框架对应,实现业务能力、应用组件、数据模型与技术栈的深度融合,为华为全球化财务核算提供核心支撑。

金牌架构师 437

多模态轨迹预测:行人、车辆的交互式推理

多模态轨迹预测:行人、车辆的交互式推理 ,人工智能,计算机视觉,大模型,AI,本文围绕多模态轨迹预测中行人与车辆的交互式推理展开,介绍了其定义,即综合多种信息预测交通参与者未来多种轨迹。涵盖基础概念如轨迹表示、模态、交互关系,技术框架包括数据处理、特征提取、预测模型(物理、机器学习、深度学习模型等)及结果评估。还探讨了交互式推理方法、面临的不确定性处理等挑战、应用场景、未来发展方向、相关工具及实际案例,展现了该技术在智能交通等领域的重要性与发展潜力。​

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 14万+

Codeforce 214A Old Peykan

A. Old Peykan time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n cities in the country where the O

Domacles 1005

Qlib:微软开源的AI量化投资平台 极简入门快速上手教程:使用 Qlib 进行中芯国际股价回测和预测

Qlib是由微软开源的面向AI量化投资的工具包。它提供了构建量化投资模型所需的基础设施,旨在帮助研究者和从业人员更高效地进行量化研究和策略开发。

AI天才研究院 5412

UVa 11264 Coin Collector (选硬币&贪心好题)

思路: 1. 你肯定注意到了,面值最大的硬币c[n-1]必须要选。(反证:如果花了sum元却没有选中它,可知sum<c[n-1],于是用m+c[n-1]元去兑换可以得到一个更优解。) 2. 贪心的关键:假设S(i)是c[1]…c[i] 中那些被选中的货币的面值的和。那么一定有 S(i) < c[i+1]。 3. 所以可以构造一个这样的序列出来。按照2中所说,如果有 S(i-1) < c[i]且S(i) =S(i-1)+c[i]<c[i+1],那么c[i]将被选中。 完整代码:

AC,∑ndless 4698

单片机:实现MPU6050的卡尔曼滤波算法(附完整源码)

单片机:实现MPU6050的卡尔曼滤波算法(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 798

华为OD技术面真题 - JAVA开发 - 1

汇总华为OD技术面八股JAVA八股,高频技术真题并提供详细解答。

qq_45776114的博客 1201

UVa 256 Quirksome Squares (枚举||二次同余)

直接从0~9999枚举即可,因为等式右边一定是个完全平方数。 PS:此题可抽象成一个数论的问题:(部分解法参考了这篇文章) 求解4个二元二次丢番图方程 (x+y)^2=2mx+y,m=10^k / 2 = 2^(k-1)*5^(2k),k=1,2,3,4 令x+y=t,上式化为 t^2-2mt+(2m-1)y=0(由于0<=t^2<10^2k,所以0<=t<10^k) 进而 (t-m)^2=(1-2m)y+m^2 此方程的等价于求解二次同余式

AC,∑ndless 3440

Claude Code auto mode 管理 subagents 的三道安全闸门

文章摘要: Claude Code的auto mode核心在于重构多代理协作的安全边界,将信任拆解为三个检查点:任务委派前评估主会话指令是否越界(v2.1.178新增);执行中强制subagent继承主会话权限模式,禁止自行降级;返回前审查完整动作历史并附加安全警告。这种设计通过动态运行时约束(classifier)与多层防线(tools限制、hooks等)结合,避免安全策略分散化。auto mode并非完全放权,而是通过减少常规提示+后台严格检查实现平衡,与隔离环境专用的bypassPermissions

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 73

UVa 10049 Self-describing Sequence (自描述序列&二分递推)

10049 - Self-describing Sequence Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=34&page=show_problem&problem=990 Solomon Golomb's self­des

AC,∑ndless 3143

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

UVa 108 Maximum Sum (贪心&最大子矩阵和)

108 - Maximum Sum Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=44 Background A problem that is simple

AC,∑ndless 2784

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

UVa 10057 A mid-summer night's dream. (二分&可以取哪些作为中位数?)

输出注意: 第一个数是最小的A,第二个数是在数列{Xn}中有多少个数可以是A,第三个数是在有多少个数可以是A。 完整代码:

AC,∑ndless 2495

Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)

A. Insomnia cure http://codeforces.com/problemset/problem/148/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2453

AOJ 0033 Ball (枚举)

题意: 有一个形似央视大楼(233)的筒,从A口可以放球,放进去的球可通过挡板DE使其掉进B裤管或C裤管里,现有带1-10标号的球按给定顺序从A口放入,问是否有一种控制挡板的策略可以使B裤管和C裤管中的球从下往上标号递增。  输入: 第一行输入数据组数N。接下来N行为N组具体数据,每组数据中有10个整数,代表球的放入顺序。  输出: 对于每组数据,若策略存在,输出YES;若不存在,输

AC,∑ndless 2325

UVa 12261 High Score (贪心&“向左走,向右走”)

12261 - High Score Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=244&page=show_problem&problem=3413 思路:注意名字中有若干个A的情况,这时对每串连续的A进行“向左走,

AC,∑ndless 2310

UVa 10125 Sumsets (折半枚举&二分查找)

10125 - Sumsets Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1066 Given S, a set of integers, find the largest d such that a + b +

AC,∑ndless 2305

UVa 1042 Lots of Sunlight (枚举&最优斜率)

1042 - Lots of Sunlight Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3483 思路:对于给定的楼层,枚举左、右的最大斜率。 at

AC,∑ndless 2222

USACO The Clocks 一种O(1)的算法

The Clocks IOI'94 - Day 2 Consider nine clocks arranged in a 3x3 array thusly: |-------| |-------| |-------| | | | | | | | |---O | |---O | | O |

AC,∑ndless 2192

UVa 200 Rare Order (拓扑排序)

200 - Rare Order Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=136 题意:给一列单词,这些单词是按一种未知的字典顺序排列的,要求输出这些字母

AC,∑ndless 2122

UVa 1193 / POJ 1328 / Beijing 2002 Radar Installation (贪心&区间选点)

1193 - Radar Installation Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3634 http://poj.org/problem?id=1328 Assume the coasting

AC,∑ndless 2081

UVa 340 Master-Mind Hints (优化查找&复制数组)

学英语: 1. Match (i,j) is called strong when i =j, and is called weak otherwise. 当i=j时,匹配(i,j)被叫做强匹配,反之叫做弱匹配。 2. Two matches (i,j) and (p,q) are called independent when i = p if and only if j = q. A set of matches is called independent when all of its members

AC,∑ndless 2063

Codeforces Round #194 (Div. 1) / 333A Secrets(贪心)

A. Secrets http://codeforces.com/contest/333/problem/A time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ge

AC,∑ndless 2041
上一篇: SGU 127 Telephone directory (模拟)
下一篇: POJ 1068 Parencodings (字符串处理)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值