需要开发者竞赛算法 [英] Developer contest algorithm needed

查看:127
本文介绍了需要开发者竞赛算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨其他开发者我正在参加我所在县的开发者竞赛,我已经完成了考试的练习任务,我已经成功完成了大部分考试但是我遇到了这个问题,特别是你能不能参加考试看看任何想法或帮助都是受欢迎的,编程语言并不重要它可以用任何语言解决,这里的任务是:



有一个算术级数写在黑板上。没有更好的事情,你发明了一个涉及它的游戏。也就是说,你擦除所有偶数并用两倍小的数字替换它们。

你重复这个程序,直到板上没有更多的偶数。

For例如,您将进展{1,2,3,4,5,6}转换为{1,1,3,2,5,3},然后再转换为{1,1,3,1,5,3 }。

当你的朋友过来时,你会让他们猜出原来的进展。

例如

让我们进步6,5,4 ,3,2,1

第一步,它变成3,5,2,3,1,1

然后它变成3,5,1,3 ,1,1

这意味着对于数字3,5,1,3,1,1,解是6,5,4,3,2,1,结果为21。

输入参数:

progress - 表示原始进度的整数数组

所有数字都被带到奇数元素

限制条件:

进展中元素的数量介于4和500之间。

每个元素进展的内容介于1和1000000之间。

所有进展元素都是奇数。

返回值:

元素的总和原始算术级数

当有多个解决方案时,返回所有元素总和较小的解决方案。

请注意,每个解决方案都有一个解决方案原始进度的数量小于1000000.

班级名称:

升读

方法签名:

public int reverse(int [] progress)

TEST CASES

测试用例1:反向({1,1,3,1,5,3})= 21

测试用例2:反向({1,1,1,1,1,1})= 6

测试用例3:反向({3,3,3,3 })= 12

测试用例4:反向({3,5,1,3,1,1})= 21

测试用例5:反向({21 ,27,33,39,45,51})= 216

测试案例6:反向({37,15,23,1,9,1}} = 117

测试案例7:反向({1019,1077,1135,1193,1251,1309,1367,1 425,1483,1541})= 12800

测试案例8:逆转({1103,2067,241,1789,825,1511,343,1233,547,955,51,677,269, 399,65,121})= 18616

测试案例9:反向({5,5,5,5,5})= 25

测试案例10:反向({5,1,11,7,17​​})= 55



我尝试过:



我第一次尝试的时候,数组中的所有元素是相同的,只是为了返回它们的总和,我创建另一个数组,其中包含第一个元素的所有元素的差异,如果第二个数组全部相同的元素,只需返回它们的总和。我不知道其他测试用例,哪个数字应该乘以2而不是。

解决方案

引用:

我正在参加我县的开发者竞赛



原则是自己找到算法。



拿一张纸和一支铅笔,尝试手工解决测试示例。

你如何进行?你的解决方法是算法,你只需要翻译一个程序。



如果我们为你解决,我们也可以参加比赛。如果您使用我们的解决方案,那将是作弊。

问题交叉发布在需要开发者竞赛算法 - Stack Overflow [ ^ ]


Hi fellow developers I'm participating in a developer contest in my county and I have got practice tasks for the exam, I have been successful with most of them however I'm having issues with this one in particular could you please take a look any ideas or assistance is welcomed, the programming language doesn't matter it can be solved in any language, here is the task:

There is an arithmetic progression written on a black-board. Having nothing better to do, you invented a game involving it. Namely, you erase all the even numbers and replace them with the numbers two times smaller.
You repeat this procedure until there is no more even numbers on the board.
For example, you transform the progression {1, 2, 3, 4, 5, 6} into {1, 1, 3, 2, 5, 3} and then once again into {1, 1, 3, 1, 5, 3}.
When your friends come over, you ask them to guess the original progression.
e.g.
Let’s take progression 6, 5, 4, 3, 2, 1
In the first step, it becomes 3, 5, 2, 3, 1, 1
Then it becomes 3, 5, 1, 3, 1, 1
This means for the numbers 3, 5, 1, 3, 1, 1 the solution is 6, 5, 4, 3, 2, 1, resulting in a sum of 21.
Input parameters:
progression - an array of integers representing the original progression after
all the numbers have been brought to odd elements
Constraints:
The number of elements in progression is between 4 and 500 inclusive.
Each element of progression is between 1 and 1000000 inclusive.
All elements of progression are odd.
Return value:
The sum of the elements of the original arithmetic progression
When there is more than one solution, return the one that has smaller sum of all the elements.
Note that there will always be a solution where each number of the original progression is smaller than 1000000.
Class Name:
Progression
Method signature:
public int reverse(int[] progression)
TEST CASES
Test Case 1: reverse({1, 1, 3, 1, 5, 3}) = 21
Test Case 2: reverse({1, 1, 1, 1, 1, 1}) = 6
Test Case 3: reverse({3, 3, 3, 3}) = 12
Test Case 4: reverse({3, 5, 1, 3, 1, 1}) = 21
Test Case 5: reverse({21, 27, 33, 39, 45, 51}) = 216
Test Case 6: reverse({37, 15, 23, 1, 9, 1}) = 117
Test Case 7: reverse({1019, 1077, 1135, 1193, 1251, 1309, 1367, 1425, 1483, 1541}) = 12800
Test Case 8: reverse({1103, 2067, 241, 1789, 825, 1511, 343, 1233, 547, 955, 51, 677, 269, 399, 65, 121}) = 18616
Test Case 9: reverse({5, 5, 5, 5, 5}) = 25
Test Case 10: reverse({5, 1, 11, 7, 17}) = 55

What I have tried:

I first tried when all elements in the array are the same, just to return their sum and I make another array with the difference of all the elements from the fist one and if the second array has all the same elements, just return their sum. I have no idea for the other test cases, which number should be multiplied by two which not.

解决方案

Quote:

I'm participating in a developer contest in my county


The principle is that you find the algorithms yourself.

Take a sheet of paper and a pencil and try to solve the tests examples by hand.
How do you proceed ? your solving method is the algorithm, you just have to translate in a program.

If we solve it for you, we can as well participate to the contest. And if you use our solution, it would be cheating.
question cross posted on Developer contest algorithm needed - Stack Overflow[^]


这篇关于需要开发者竞赛算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆