On June 01 2017 01:00 Hanh wrote:
What would an algorithmic solution be?
What would an algorithmic solution be?
What the guys above you did.
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Acrofales
Spain17849 Posts
May 31 2017 17:00 GMT
#17681
On June 01 2017 01:00 Hanh wrote: What would an algorithmic solution be? What the guys above you did. | ||
Deleted User 3420
24492 Posts
May 31 2017 19:38 GMT
#17682
It is okay for me to post homeworks, and to discuss them. I figure you guys will probably find this fun so I am posting it, I'll post my attempt before I read any solutions. Assume you have a necklace of stones. Some of the stones have positive value and some have negative value. You have the opportunity to snip the necklace in two places (creating two bands) and weld the endpoints of one of the two bands back into a necklace. You would like your new necklace to be as valuable as possible. You can assume the necklace has n stones with values v[0], v[1], . . . , v[n − 1]. ah, so we have a circular connecting necklace and you snip it in 2 places, using one of the new bands to make a new necklace (a) Give an algorithm to find the value of the new necklace. If all of the stones have negative value your answer should be 0. Make your algorithm as clean and elegant as possible. (b) Give an algorithm to determine where you should snip the original necklace (not just its value). Make your algorithm as clean and elegant as possible. If all of the values are positive you should not snip and your algorithm should print: Do not snip. If all of the values are negative you should not snip and your algorithm should print: Throw necklace away. If possible the algorithm should determine these two situations without explicitly checking for them. | ||
CecilSunkure
United States2829 Posts
May 31 2017 19:49 GMT
#17683
"Some have positive, some have negative", why can't we say signed integers? It's just signed integers. It sounds like one of those "maximal subset" problems. I hate those problems man. Actually this problem here is my least favorite programming question I have ever heard, and sounds pretty similar to yours. Edit: When it says clean and elegant, what do those terms even mean. Those are really subjective terms. It sort of sounds like "try to find the trick that makes this problem easy to solve", like the trick in the wikipedia page. | ||
Deleted User 3420
24492 Posts
May 31 2017 19:57 GMT
#17684
I think that interestingly enough this question is almost the opposite of question 1 of the 3 questions I posted back a little bit ago. For the sake of familiarity I would view the necklace as a circular array (just "decide" that the ends connect) | ||
Blisse
Canada3710 Posts
May 31 2017 20:05 GMT
#17685
Of course, part of the course is learning how to decipher word problems. | ||
Acrofales
Spain17849 Posts
May 31 2017 20:05 GMT
#17686
E: re Blisse + Show Spoiler + Yeah. That. Just have to make sure you copy the values twice, so you get the fact that the first and last element are connected. Alternatively you could loop an extra time at the end until your previous value is greater or equal to the newest one. | ||
Deleted User 3420
24492 Posts
May 31 2017 20:21 GMT
#17687
For example if our necklace is: 5 7 -2 5 -2 and then we return back the whole necklace - we are wrong. (or if you don't like this example, replace with much bigger more complicated examples) I know of dynamic programming but I haven't really done much of it in practice. I think I will be okay though since I know the premise behind it. | ||
CecilSunkure
United States2829 Posts
May 31 2017 20:29 GMT
#17688
| ||
Deleted User 3420
24492 Posts
May 31 2017 20:32 GMT
#17689
| ||
CecilSunkure
United States2829 Posts
May 31 2017 20:34 GMT
#17690
| ||
Acrofales
Spain17849 Posts
May 31 2017 20:38 GMT
#17691
On June 01 2017 05:29 CecilSunkure wrote: What's wrong with returning the whole array? In that example? It doesn't maximize the value. By just returning [5, 7] you get a value of 12. If you add negative values, your value isn't maximal. @Travis: you don't want a minimal length. You don't want maximal length. You want maximal value, which is what blisse's link describes. E: I read -5 for the second 5 :p. But even so you don't want to return the whole array ![]() | ||
Deleted User 3420
24492 Posts
May 31 2017 20:43 GMT
#17692
Which, actually is that problem. But making it circular changes it a bit. I know we don't want maximal or minimal length, but I am now seeing there really is no difference between looking for minimum subarray or looking for maximum subarray. | ||
CecilSunkure
United States2829 Posts
May 31 2017 20:44 GMT
#17693
And yeah... TL links seem to have lost their luster. It's impossible to see them. | ||
Deleted User 3420
24492 Posts
May 31 2017 20:53 GMT
#17694
I don't think Blisse's link does it justice - the trouble for me is in handling that it is circular. edit: I looked up an answer and it's really cute - you guys were underselling this problem ![]() a hint is that my intuition was right that I needed to find the maximum negative subarray, but there is more to it than that. | ||
CecilSunkure
United States2829 Posts
May 31 2017 21:37 GMT
#17695
![]() | ||
Acrofales
Spain17849 Posts
May 31 2017 21:54 GMT
#17696
+ Show Spoiler +
| ||
Deleted User 3420
24492 Posts
May 31 2017 22:14 GMT
#17697
I don't know what language that is, but I am guessing what you are doing is 1.) make an array that repeats the original array once 2.) find the maximum continuous subarray. 3.) if the maximum continuous subarray is greater in length than the original array, don't cut {5, 5, -1, 5, -1, 5} would return "don't cut", which would be wrong because the correct answer would remove an instance of -1 | ||
Blisse
Canada3710 Posts
May 31 2017 22:39 GMT
#17698
edit: oo, neat lol | ||
Acrofales
Spain17849 Posts
May 31 2017 22:40 GMT
#17699
On June 01 2017 07:14 travis wrote: edit2: I don't know what language that is, but I am guessing what you are doing is 1.) make an array that repeats the original array once 2.) find the maximum continuous subarray. 3.) if the maximum continuous subarray is greater in length than the original array, don't cut {5, 5, -1, 5, -1, 5} would return "don't cut", which would be wrong because the correct answer would remove an instance of -1 It is pseudopython. Mostly python, but too lazy to make it properly. And yeah, completely interested code. Unless I made a mistake somewhere, it'd return 5, 4 as the start and end for your cut, which is what you'd want. The loop would end with 5, 10 as the maxstart, maxend. Those would then be adjusted (just the maxend in this case) to not be greater than the necklace's length. | ||
Deleted User 3420
24492 Posts
May 31 2017 22:58 GMT
#17700
I thought I had a clue reading that code but maybe I don't, lol | ||
| ||
![]() StarCraft 2 StarCraft: Brood War Britney Dota 2![]() ![]() Calm ![]() Horang2 ![]() GuemChi ![]() Pusan ![]() BeSt ![]() Hyuk ![]() Harstem ![]() Larva ![]() Mong ![]() [ Show more ] Counter-Strike Other Games summit1g10822 singsing1937 hungrybox319 B2W.Neo291 SortOf268 Pyrionflax267 Fuzer ![]() nookyyy ![]() Lowko41 Dewaltoss34 kaitlyn30 Mew2King27 ZerO(Twitch)23 JuggernautJason8 Organizations Other Games StarCraft: Brood War StarCraft 2 StarCraft: Brood War
StarCraft 2 • LUISG StarCraft: Brood War![]() • AfreecaTV YouTube • intothetv ![]() • Kozan • IndyKCrew ![]() • LaughNgamezSOOP • Migwel ![]() • sooper7s League of Legends |
WardiTV Map Contest Tou…
Creator vs MaxPax
Rogue vs Creator
MaxPax vs Rogue
Spirit vs Creator
Spirit vs Rogue
Spirit vs MaxPax
Code For Giants Cup
WardiTV Map Contest Tou…
Jumy vs Zoun
Clem vs Jumy
ByuN vs Zoun
Clem vs Zoun
ByuN vs Jumy
ByuN vs Clem
The PondCast
WardiTV Map Contest Tou…
Replay Cast
WardiTV Map Contest Tou…
SC Evo Complete
Classic vs uThermal
SOOP StarCraft League
CranKy Ducklings
[ Show More ] SOOP
WardiTV Map Contest Tou…
[BSL 2025] Weekly
SOOP StarCraft League
Sparkling Tuna Cup
WardiTV Map Contest Tou…
uThermal 2v2 Circuit
uThermal 2v2 Circuit
|
|