问题描述
我对编码还很陌生,我正在尽力而为,但是经过数小时的研究,我仍然无法弄清这一点。我正在尝试通过最少的移动使这两个单独的数组相同。我一次只能++或-一个数字。
这是挑战:
不允许对数字重新排序例如,考虑两个数组:Andrea的[123,543]和Maria的[321,279]。对于第一个数字,Andrea可以将1递增两次以达到3。2已经相等。最后,她将3减2等于1。花了4步才能达到目标。对于第二个整数,她递减5 3次,递增4 3次和3 6次。花了12步来转换第二个数组元素。总共花了16步来转换组成整个数组的两个值。
# Complete the 'minimumMoves' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER_ARRAY a
# 2. INTEGER_ARRAY m
#
minimumMoves <- function(a,m) {
# Write your code here
}
stdin <- file('stdin')
open(stdin)
fptr <- file(Sys.getenv("OUTPUT_PATH"))
open(fptr,open = "w")
aCount <- as.integer(trimws(readLines(stdin,n = 1,warn = FALSE),which = "both"))
a <- readLines(stdin,n = aCount,warn = FALSE)
a <- trimws(a,which = "both")
a <- as.integer(a)
mCount <- as.integer(trimws(readLines(stdin,which = "both"))
m <- readLines(stdin,n = mCount,warn = FALSE)
m <- trimws(m,which = "both")
m <- as.integer(m)
`enter code here`result <- minimumMoves(a,m)
`enter code here`writeLines(as.character(result),con = fptr)
enter code here
close(stdin)
close(fptr)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)