ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

【CF1512F Education】题解

2022-06-11 09:01:06  阅读:172  来源: 互联网

标签:Now Polycarp 题解 CF1512F position tugriks Education day he


题目链接

题目

有一个长度为 \(n\) 的数组 \(a\) 和一个长度为 \(n−1\) 的数组 \(b\),初始位置为 \(pos=1\),每一天可以选择得到 \(a_{pos}\)元钱,或者花费 \(b_{pos}\)元钱(钱数不能为负)使得 \(pos\leftarrow pos+1\)

现在希望买一台 \(c\) 元的电脑,最少需要多少天。

Polycarp is wondering about buying a new computer, which costs $ c $ tugriks. To do this, he wants to get a job as a programmer in a big company.

There are $ n $ positions in Polycarp's company, numbered starting from one. An employee in position $ i $ earns $ a[i] $ tugriks every day. The higher the position number, the more tugriks the employee receives. Initially, Polycarp gets a position with the number $ 1 $ and has $ 0 $ tugriks.

Each day Polycarp can do one of two things:

  • If Polycarp is in the position of $ x $ , then he can earn $ a[x] $ tugriks.
  • If Polycarp is in the position of $ x $ ( $ x < n $ ) and has at least $ b[x] $ tugriks, then he can spend $ b[x] $ tugriks on an online course and move to the position $ x+1 $ .

For example, if $ n=4 $ , $ c=15 $ , $ a=[1, 3, 10, 11] $ , $ b=[1, 2, 7] $ , then Polycarp can act like this:

  • On the first day, Polycarp is in the $ 1 $ -st position and earns $ 1 $ tugrik. Now he has $ 1 $ tugrik;
  • On the second day, Polycarp is in the $ 1 $ -st position and move to the $ 2 $ -nd position. Now he has $ 0 $ tugriks;
  • On the third day, Polycarp is in the $ 2 $ -nd position and earns $ 3 $ tugriks. Now he has $ 3 $ tugriks;
  • On the fourth day, Polycarp is in the $ 2 $ -nd position and is transferred to the $ 3 $ -rd position. Now he has $ 1 $ tugriks;
  • On the fifth day, Polycarp is in the $ 3 $ -rd position and earns $ 10 $ tugriks. Now he has $ 11 $ tugriks;
  • On the sixth day, Polycarp is in the $ 3 $ -rd position and earns $ 10 $ tugriks. Now he has $ 21 $ tugriks;
  • Six days later, Polycarp can buy himself a new computer.

Find the minimum number of days after which Polycarp will be able to buy himself a new computer.

思路

从前往后枚举每个位置,设其为整个过程到达的最右的位置。

枚举的过程可以记录当前过程中 \(a_i\) 的最大值,然后当前过程中加的话只加这个词。

到达每个位置后在计算一下当前要达到 \(c\) 的最小值,最后再取个最小值就是答案。

Code

// Problem: CF1512F Education
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/CF1512F
// Memory Limit: 250 MB
// Time Limit: 2000 ms

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
#define N 200010
//#define M
//#define mo
int n, m, i, j, k, T; 
int a[N], b[N], d, s, ans, mx, c; 

int Z(int x, int y)
{
	return x/y+(x%y ? 1 : 0); 
}

signed main()
{
//	freopen("tiaoshi.in","r",stdin);
//	freopen("tiaoshi.out","w",stdout);
	T=read(); 
	while(T--)
	{
		d=-1; s=mx=0; ans=0x7fffffff; 
		n=read(); c=read(); 
		for(i=1; i<=n; ++i) a[i]=read(); 
		for(i=2; i<=n; ++i) b[i]=read(); 
		for(i=1; i<=n; ++i)
		{
			if(s<b[i]) d+=Z(b[i]-s, mx), s+=Z(b[i]-s, mx)*mx; 
			++d; s-=b[i]; mx=max(mx, a[i]); 
			if(s<c) ans=min(ans, d+Z(c-s, mx)); 
			// printf("%lld %lld %lld\n", s, d, ans); 
		}
		printf("%lld\n", ans); 
	}
	return 0;
}

总结

这道题一开始盲猜是dp,最后发现其实是个很简单的贪心。

核心思想中很重要的一个,就是当前过程如果加就只在当前最大值停留。

感觉和以前的一道什么湖边钓鱼很像。

标签:Now,Polycarp,题解,CF1512F,position,tugriks,Education,day,he
来源: https://www.cnblogs.com/zhangtingxi/p/16365234.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有