【动态规划】Integer Percentage

1138. Integer Percentage

Time Limit: 1.0 second
Memory Limit: 16 MB
Applying for a new job, programmer N. Smart required that his new salary (in rubles, positive integer) would be greater than his previous salary by integer percentage. What could be the highest possible number of previous jobs for mister Smart, if his latest salary did not exceed n rubles and his first salary was exactly s rubles?
Example. Let n = 10, s = 2, then m = 5. The sequence 2, 4 (+100%), 5 (+25%), 8 (+60%), 10 (+25%) is the longest (although not unique) sequence that satisfies to the problem statement. Salary increase percentage is written inside the brackets.
Problem illustration

Input

Two integers n and s separated by one or more spaces. 1 ≤ n, s ≤ 10000.

Output

A single integer m — the maximum number of N. Smart’s previous jobs.

Sample

inputoutput
10 2
5

Hint

if n = s, the answer is 1.
 
简单得很的一道动规题,但是没有看懂题意。一是最终工资不用一定等于n,可以小于等于n。二是,输出最多的工作数,而不是在满足工资最接近n时最多的工资数。
 
#include <cstdio>
#include <cmath>
#define MAX(a,b) ((a)>(b)?(a):(b))
long f[3000000];
int main()
{
	freopen("ip.in","r",stdin);
	freopen("ip.out","w",stdout);
	long n, s;
	if (n == s)
	{
		printf("0");
		return 0;
	}
	scanf("%ld%ld",&n,&s);
	f[s] = 1;
	long ans = 1;
	for (long i=s;i<n+1;i++)
	{
		for (long j=1;j<101 && i*100+i*j<n*100+1;j++)
		{
			if (!((i*j) % 100))
			{
				if (f[i] && f[i]+1 > f[i+i*j/100])
				{
					f[i+(i*j)/100] = f[i]+1;
					ans = MAX(ans,f[i+(i*j)/100]);
				}
			}
		}
	}
	printf("%ld",ans);
	return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
解释下这段代码。Sub CopyLog() Dim sourceSheet As Worksheet Dim targetWorkbook As Workbook Dim targetSheet As Worksheet Dim lastRow As Long Dim cell As Range Dim percentage As Double Dim copyRange As Range Dim pasteSheet As Worksheet Dim pasteIndex As Long Dim R As String Dim u As Integer With ThisWorkbook.Worksheets("fileN").Range("A1") u = ThisWorkbook.Sheets("fileN").Range("B" & Rows.Count).End(xlUp).Row Do Until u = 1 R = .Cells(u, "B").Value .Cells(1, 4) = R ' 设置源工作表的引用 Set sourceSheet = ThisWorkbook.Sheets(R) ' 获取目标工作簿的引用 Set targetWorkbook = Workbooks("dailylog.xlsx") ' 获取源工作表的最后一行 lastRow = sourceSheet.Cells(sourceSheet.Rows.Count, "C").End(xlUp).Row pasteIndex = 0 ' 循环遍历源工作表的C列(从第二行开始) For Each cell In sourceSheet.Range("C2:C" & lastRow) ' 获取对应行的H列数值 percentage = CDbl(sourceSheet.Range("H" & cell.Row).Value) ' 判断是否满足条件(H列数值小于等于-1%) If percentage <= -0.01 Then ' 设置复制范围前7个单元格 Set copyRange = sourceSheet.Range("A" & cell.Row & ":H" & cell.Row) ' 获取目标工作表和粘贴位置 Set pasteSheet = targetWorkbook.Sheets(targetWorkbook.Sheets.Count - pasteIndex) ' 将符合条件的行以文本形式复制粘贴到目标工作表的指定位置 copyRange.Copy pasteSheet.Cells(pasteSheet.Cells(pasteSheet.Rows.Count, "A").End(xlUp).Row + 1, "A").PasteSpecial xlPasteValues End If ' 每次循环将粘贴位置后移一位 pasteIndex = pasteIndex + 1 Next cell u = u - 1 Loop targetWorkbook.Save ' 提示复制粘贴完成 MsgBox "数据已成功复制粘贴到'dailylog.xlsx'的指定位置!" End With End Sub
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值