language-agnostic

What is the best data structure for keeping the top n elements in sort order?

僤鯓⒐⒋嵵緔 提交于 2020-01-01 10:45:45
问题 I am looking for a data structure which keeps the top n elements, similar to this question, but with the added requirement of maintaining sort order. Obviously I could just sort at the end but there might be a more efficient way to do it on the fly. There will only be insertions, never removals, and then an iteration through the top n elements at the end. This question is language agnostic but it will be in C# so an answer that uses native .NET collections is preferable. EDIT: I should

Fill volume algorithm

帅比萌擦擦* 提交于 2020-01-01 08:57:05
问题 I have a Box with some dimension length, width, height. I have items with different length, width, height. Is there an existing algorithm that can determine the best items to use to put inside the box? 回答1: This is called a Bin Packing/Cutting Stock/Knapsack problem, and it is NP hard. In general you can only get an approximate solution by using heuristics, see for example http://en.wikipedia.org/wiki/Knapsack_problem http://en.wikipedia.org/wiki/Bin_packing_problem http://en.wikipedia.org

Avoiding repeat of code after loop?

会有一股神秘感。 提交于 2020-01-01 07:55:08
问题 I often end up writing a bit of code twice when using a loops. For example, while going over the Udacity computer science course, I wrote the code (for a function to find the most sequentially repeated element): def longest_repetition(l): if not l: return None most_reps = count = 0 longest = prv = None for i in l: if i == prv: count += 1 else: if count > most_reps: longest = prv most_reps = count count = 1 prv = i if count > most_reps: longest = prv return longest In this case, I'm checking

Corner Stitching Datastructure, Any Open Source Implementations? [closed]

时光毁灭记忆、已成空白 提交于 2020-01-01 07:20:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I recall learning about the corner-stitched data structure a number of years ago and have been fascinated with it ever since. It originated with a paper by Ousterhout. I've searched and not been able to find a free/open implementations. I'd prefer a C++ implementation, but at this point would accept any pointers

Win32: Is it possible to build an app that houses other apps?

筅森魡賤 提交于 2020-01-01 06:25:21
问题 I was wondering, how would you go about writing an application that basically houses other applications inside of it? The reason I ask is that I'd love to build an app that 'conquers' my current explosion of open windows. I've used virtual window managers before and they're nice and all, but I could do so many things with an app like I mention. Alternatively does anyone know of an easy to use/intuitive application for confining windows to 'regions' of your screen? Something like GridMove, but

How to handle different protocol versions transparently in c++?

江枫思渺然 提交于 2020-01-01 05:02:23
问题 This is a generic C++ design question. I'm writing an application that uses a client/server model. Right now I'm writing the server-side. Many clients already exist (some written by myself, others by third parties). The problem is that these existing clients all use different protocol versions (there have been 2-3 protocol changes over the years). Since I'm re-writing the server, I thought it would be a great time to design my code such that I can handle many different protocol versions

Graceful degradation - when to consider

拜拜、爱过 提交于 2020-01-01 04:59:09
问题 When designing and building the UI for an application that uses AJAX, when do you consider graceful degradation (for users who have JavaScript disabled, or are using a screen reader)? At the end, once the AJAX version of the site is completely finished At every stage of development I don't Something else... 回答1: These days, Progressive Enhancement is generally preferred over Graceful Degradation - i.e. the exact opposite approach. 回答2: The method I'm employing so far is to write it so it

Reliable way to (programmatically) compare PDFs? [duplicate]

痴心易碎 提交于 2020-01-01 04:52:12
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Tool to compare large numbers of PDF files? I am in the classic scenario where the business gives you a bunch of new pdf forms for the new year with no revision notes whatsoever and you are supposed to figure out what's different from the previous year ones. I am talking loads of forms here, so I am trying to find a way to compare PDFs to outline differences without having people to manually go through each and

What to do, if debug behaviour differs from normal execution? [closed]

元气小坏坏 提交于 2020-01-01 04:38:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago . I have a problem with debugging sessions. My program executes very well in a debug session but if I start a normal run, it behaves completely different. The problem is, that I cannot say, why it acts different. One possible reason is the slower execution time because you alway

computer vision: extracting info about a shape given a contour (e.g. pointy, round…)

被刻印的时光 ゝ 提交于 2020-01-01 03:31:05
问题 Given the 2D contour of a shape in the form of lines and vertices, how can I Extract Information from that? like: Pointy, round, straight line. Shape similarities with a given shape. Code is not necessary, I am more interested in concepts and the names of techniques involved to guide my search.... Thanks in advance. 回答1: Image moments One approach is to calculate the first and second order central moments of the shape described by the 2D contour. Using these values the elongation of the