Search found 56 matches

by jakabjr
Thu Jun 19, 2008 10:44 am
Forum: Algorithms
Topic: Bar cutting problem
Replies: 0
Views: 1212

Bar cutting problem

I have to write an algorithm to optimize cutting smaller bars from a minimum number of full length (uncut) bars. The full length of an entire (uncut) bar is 1200. Then I get a set of smaller bars in length&number pairs like 12bars of length 350, 6bars of length 400, etc. The problem is to find the b...
by jakabjr
Fri Jun 24, 2005 10:04 am
Forum: Algorithms
Topic: algorithm/ideas needed
Replies: 4
Views: 1658

actually, a 6 side triangle can be broken into 9 2-side triangles that cover the exact same area. So, whatever u can cover with a 6 sider, u can also cover with 2 side triangle. /\ /\ / \ /\ /\ /____\ / \/ \/\ something like that, with 5,3 and 1 2 side triangles on the rows.
by jakabjr
Thu Jun 23, 2005 2:54 pm
Forum: Algorithms
Topic: algorithm/ideas needed
Replies: 4
Views: 1658

sorry, ah = lh*lh*sqrt(3)*3/2
by jakabjr
Thu Jun 23, 2005 2:50 pm
Forum: Algorithms
Topic: algorithm/ideas needed
Replies: 4
Views: 1658

i have no theorem to back me up, but here's a guess: if lh is the hexagon's side length, ah it's area, lt1..ltn the triangle sides and atn their areas, then if u can write lh as a sum of lt1..ltn and ah as a sum of at1..atn then i belive the hexagon can be splited. at = lt *lt *sqrt(3)/4; ah = lh*lh...
by jakabjr
Thu Jun 23, 2005 1:42 pm
Forum: Algorithms
Topic: Usaco problem (contact) in section 2.1
Replies: 6
Views: 1788

hi. my idea is something like: generate all possible sequences in A-B bit range and convert to a string. use the strstr function to go through the message string and count occurences. of course, if a=1 and b=12 there are a lot of cases, but there is a catch: 00 will allways have less occurences than...
by jakabjr
Mon Jun 06, 2005 12:34 pm
Forum: Volume 1 (100-199)
Topic: 119 - Greedy Gift Givers
Replies: 145
Views: 25715

i think ur problem is that when (mon_hav/num_rec) yields a remainder, u loose that money, which should be added to rec[nth_per].
in the first example, dave gives 200 to 3 people. that means 198 is given and 2 remains to him. after getting 300 from others, he has in the end 302.
by jakabjr
Fri Jun 03, 2005 2:22 pm
Forum: Algorithms
Topic: Panel
Replies: 5
Views: 1277

hi. i assume BF comes from brute force. also i assume by BF in this case u mean the one presented on the page for the easy test-case. what is the monte-carlo solution? what euristic method have u used, the one they present? please clarify theese things to me. here's some math i did on this. is it ac...
by jakabjr
Fri Jun 03, 2005 12:08 pm
Forum: C
Topic: quicksort built in
Replies: 8
Views: 8355

using a->key - b->key is dangerous because of overflow!
if u r not sure it will fit (in the example into int), u shuold use ifs with
<,> or typecast one of them to a larger type (in the example long will do).
by jakabjr
Fri Jun 03, 2005 12:02 pm
Forum: C
Topic: about using "sscanf" :=)
Replies: 5
Views: 3704

actually, "%s" skips all preceeding blank spaces (specified in isspace() for instance), which are more then " ", "\n" and "\r". (the tab is a blank surely "\t"). as for reding from a string, here's a good topic, which gives u all the solutions u need: http://acm.uva.es/board/viewtopic.php?t=7539&sid...
by jakabjr
Fri Jun 03, 2005 11:42 am
Forum: C
Topic: scanf in 10013!
Replies: 1
Views: 2193

more generally, if u need to skip any number of blank spaces (which are specified by isspace() for instance), u can also use scanf(" ");
the "%s", "%d", "%f" type conversion specifiers do this implicitly.
by jakabjr
Fri Jun 03, 2005 11:27 am
Forum: C
Topic: Things that produce compile error
Replies: 3
Views: 3531

well, u use double type as index for an array.
that's a no-no. if u're sure the values are integer, u can cast, but carefull for overflow & precision.
by jakabjr
Fri Jun 03, 2005 11:24 am
Forum: C
Topic: Weird Invalid Memory Reference?
Replies: 5
Views: 3101

also interested. can u post the code?
an idea: maybe u forgot the & in scanf...
by jakabjr
Fri Jun 03, 2005 10:33 am
Forum: C
Topic: malloc
Replies: 17
Views: 8406

a very interesting thing i've never seen b4 was the int **a = (int **)calloc(10*10,sizeof(int)); a[0][2]=3 yes, triky way to get rid of some sintax, but let's see what happens, actually. The "sintactic sugar for pointer arith" that moebius was talking about is somethig like a = *(a+i), where a is an...
by jakabjr
Wed Jun 01, 2005 3:45 pm
Forum: C
Topic: Passing bidimentional mtrx to functions as pointer argument
Replies: 3
Views: 2221

it is possible to pass anything, it's just that things get complicated fast the more u reference. if u have int mat[N][M]; => void doSomething(int m[][M]); //or int *m[M] (this is an array of arrays of int) int *mat[M]; => void doSomething(int *m[M]); // or int **m (this is an array of pointers to i...
by jakabjr
Wed Jun 01, 2005 3:13 pm
Forum: C
Topic: Exchanging two integers
Replies: 5
Views: 3011

besides, this is defined by ANSI C as undetermination:
a ^= b ^= a ^= b;
since u are trying to modify and access a variable in at the same point of execution.
it might work, but it's not portable.

Go to advanced search