|
I should add one more stipulation, the two groupings must both have the same number of elements (or one off if an odd number of total elements).
for example, if I had elements with values: 1, 5, 19, 10
and I wanted the best 2 groupings, I would get:
{ 19, 1 }, { 10, 5 }
{ 19, 5 }, { 10, 1 }
I hope that clarifies things. It will be a fair amount of calculations, but it shouldn't be too bad because the maximum number of elements (in this case) is 20. That and I can't think of a better way :/
|
|
|
|
|
Are there any limitations on the number of items in each group, or can one group have many more items as long as the totals are close?
An easy way to find all combinations is too look at each item belonging to either group as a bit value. If you have 8 items you need 8 bits to represent which group they belong to, so there are 256 (2^8) ways of dividing the items into two groups if there is no limitations on the number of items in each group.
If you place the (rather obvious) limitation that each group has to contain at least one item, you have (2^n)-2 combinations, where n is the number of items.
---
b { font-weight: normal; }
-- modified at 12:44 Thursday 2nd February, 2006
|
|
|
|
|
I editted my main post to include the limitation that both groups must have an as-close-to-equal-as-possible number of elements.
|
|
|
|
|
Which is more important then, the difference in total sum, or the difference in number of elements?
---
b { font-weight: normal; }
|
|
|
|
|
the [lack of] diffrence in number of elements is more important
|
|
|
|
|
Then you only have to do the actual calculation for those combinations where the difference is low enough. Loop through the combinations and count the bits, and if the difference between zeroes and ones are low enough, calculate the sums. You can keep a sorted list with the best results so that you easily can add results that are better than the previous.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I'm doing a windows app and I need to know if the user pushed the red X button in the top right of my form.
I know the Form_closing has an enum telling the reason of the form close, but it doesnt specify if it was my own cancel button or the X button, and I need to know it.
Any ideas?
Thanks in advance
|
|
|
|
|
public class MyForm:Form<br />
{<br />
private bool _cancelButtonClicked = false;<br />
private void cancelbutton_clicked(..)<br />
{<br />
_cancelButtonClicked = true;<br />
}<br />
private void form_closing(..)<br />
{<br />
if (_cancelButtonClicked)<br />
{<br />
}<br />
else<br />
{<br />
}<br />
}<br />
}
- Malhar
|
|
|
|
|
Yeah, well...thanks for the reply, but I was looking for a non-flag solution, thats the easy way
|
|
|
|
|
That's also the only way you can tell the difference.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Damn...thats bad. Thanks for your help guys
|
|
|
|
|
hi chals!
try this:
private const int WM_SYSCOMMAND = 0x112;
private const int SC_CLOSE = 0xF060;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE)
{
}
}
messages under WM_SYSCOMMAND includes:
- Restore, Move, Size, Minimize, Maximize & Close (x button in the forms) or the commands in the context menu when you right click the title bar of a window.
the SC_CLOSE WParam is for the close command.
you can look for other commands in the WinUser.h file of Visual Studios. most of the time it is in "C:\Program Files\Microsoft Visual Studio .NET\Vc7\PlatformSDK\Include\" folder. It has the list of constants for API commands.
hope that helps!
microsoc
|
|
|
|
|
Thanks!!! That worked like a charm
|
|
|
|
|
nice to know that!
happy coding!
microsoc
|
|
|
|
|
Hi,
just across a silly problem whilst coding.
Have a menustrip, in the following layout:
menustrip1
---------File
-------------Connect to DB
-------------Disconnect from DB
Obviously the two menuitems need to be enabled and disabled at various stages of the application.
But the problem is, I cant access them!
ok, menustrip1.Items[0] will return me the "File" menu object.
But I cant find the collection within that object to reference the menuitems.
There is no Items object and there is no dropdownitems object.
I expected to be able to do something like:
menustrip1.Items[0].items[0].enabled = true;
or even
menustrip1.items["File"].Items["Connect to DB"].Enabled = true;
but this context doesnt exist
So Anyone know?
|
|
|
|
|
Found the solution.
If anyone is interested...
<br />
System.Windows.Forms.ToolStripMenuItem mi = (ToolStripMenuItem)menuStrip1.Items[0];<br />
mi.DropDownItems[0].Enabled = false;
First time will return the File menu as an object, the second will drill down to the sub menuitems!!
|
|
|
|
|
Oh .. I just noticed "vs2005" in your subject line!
|
|
|
|
|
I have a PictureBox in a Windows Forms app. I can load a GIF, JPG or BMP. Is there a way to designate a transparent color for the background in a PictureBox?
Thanks,
Mark
|
|
|
|
|
IIRC, the PictureBox doesn't support a transparent background.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
If the file format supports transparency (GIF/PNG), then it works.
There is no way to specify what the transparent colour is manually.
|
|
|
|
|
Hi,
I'd like to put a transparent label over a textbox. I set the label backcolor to transparent and set its parent as the textbox. But setting the textbox as the parent results in the label not coming up at all (I changed the backcolor to red so I could see if it was there). Anyone know what to do?
Thanks!!!
Mel
|
|
|
|
|
Why did you set the textbox as the labels parent? There's no need to do this. All you have to do is call the labels BringToFront method to get it sit on top of other controls.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
while(flag == 0)
{
if(eq[i]=='0' || eq[i]=='1' || eq[i]=='+' || eq[i]=='\'') // the exception is here
{
switch(eq[i])
{
case'1':
{
if (!operator_flag)
{
new_equation[i] = 2;
new_equation[i+1] = 1;
...etc}
else
{
MessageBox.Show("Not Boolean Equation" );
flag = 1;
}
i++;
}
I got unhandled exception in the first if statement and i don't know what to do about it, can anyone give any help!!
thanks in advance
joly_1
-- modified at 11:06 Thursday 2nd February, 2006
|
|
|
|
|
Look at the inner exception. Or put a try/catch on the method that's calling the while loop. It'll tell you the exception type/stacktrace etc.
|
|
|
|
|
Well, i got this:
Index outside the bounds of the array.
so, what i should do about it?
joly_1
|
|
|
|