Re: [algogeeks] Re: printing without loop

2011-03-05 Thread Bhavesh agrawal
funny but correct ,i have a code of 100 lines of file named b.cpp
so i use awk script to print only no. of lines and i got the exact desired
result .





#includecstdlib
using namespace std;
int main()
{
system(awk '{print NR}' b.cpp);

}

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] problem

2011-03-05 Thread Akash Mukherjee
Hi,

I need some help. I am still a nube so if this is too easy, plz don't flame.
I cannot understand how to approach the problem. Would appreciate any help.

At CodeChef, The Chef can make 10 types of dishes numbered 0 through 9. He
can however only make dishes one after another. Suppose The Chef made dishes
1, 4, 2, 1, 2, 1 on a given day, the number configuration that day would be
142121. On a given day, he makes any number of dishes as long as:

   1. The number configuration for that day is greater than zero(0) and less
   than or equal to 'N'.
   2. Dish 3 is never made *after* dish 1 has been made.
   3. Dish 0 is never the first dish of the day, to be prepared.


How many such unique number configurations exist for a given 'N'?

Examples:

   - 1 is a valid configuration
   - 52 is a valid configuration
   - 12 is a valid configuration
   - 32 is a valid configuration
   - 321 is a valid configuration
   - 3231 is a valid configuration
   - 120 is a valid configuration
   - 012 is not a valid configuration
   - 123 is not a valid configuration
   - 32123 is not a valid configuration

 The first line of the input will contain a number T (1 ≤ T ≤ 1000)
containing the number of test cases. Each line that follows is a separate
test case which has exactly 1 integer 'N' (1 ≤ N  1018). For each case,
output a single line containing the number of configurations possible for
that 'N'.
*Sample Input:*

5
10
15
115
1113
123456789

*Sample Output:*

10
14
112
1064
92470733

Thanks
Akash

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Re: B Boxes N Dollars Make Money fro it

2011-03-05 Thread Anuj Agrawal
On Sat, Mar 5, 2011 at 5:37 PM, Gopi kodaligopi...@gmail.com wrote:
 n = 2^(b-1)

Shouldn't this be n = SUM (2^k) where k = 0 to b-1?

 each box should have x dollars where x is of from 2^y, y ranges from 0
 to (b-1).

 On Mar 5, 9:12 am, CodeTrooper anujagrawa...@gmail.com wrote:
 I guess solution would be based on prime numbers.

 On Mar 5, 3:11 am, bittu shashank7andr...@gmail.com wrote:







  “You have b boxes and n dollars. If I want any amount of money from 0
  to n dollars, you must be able to hand me 0 to b boxes so that I get
  exactly what I request.” The two questions were “What are the
  restrictions on b and n, and how is money distributed among the
  boxes?”

  Thanks
  Shashank

 --
 You received this message because you are subscribed to the Google Groups 
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to 
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: B Boxes N Dollars Make Money fro it

2011-03-05 Thread Dave
@Bittu: There are 3 cases:
1. If n = 2^b - 1, then put $1, $2, $4, ..., $(2^(b-1)) in the boxes.
2. If n  2^b - 1, then there is some freedom in how to distribute the
dollars into the boxes. One way that works is to put $1, $2, $4, ...
(powers of two dollars) into as many boxes as you can, and then
distribute the remaining dollars among the remaining boxes in any way
that you want.
3. If n  2^b - 1, then there is no distribution of the dollars that
works. This is the restriction on b and n that you asked about.

An example of case 2 is b = 4 and n = 10. Put $1, $2, $4, and $3 into
the boxes.

Dave

On Mar 4, 4:11 pm, bittu shashank7andr...@gmail.com wrote:
 “You have b boxes and n dollars. If I want any amount of money from 0
 to n dollars, you must be able to hand me 0 to b boxes so that I get
 exactly what I request.” The two questions were “What are the
 restrictions on b and n, and how is money distributed among the
 boxes?”

 Thanks
 Shashank

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Search element in 2D row-wise colum-wise sorted matrix

2011-03-05 Thread albert theboss
the quadinary search will work well for this problem...


step 1 : divide the matrix into 4 almost equal quadrands

step 2 : being row wise sorted and column wise sorted the smallest value
will be at the top left and largest value will be at the bottom right... if
the value to be searched is within the range between largest and smallest
recursively perform step 1 until 2x2 matrix 

step 3: if it 2X2 matrix search the element individually..

complexity of this algorithm will be log4(n*m),

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] SPOJ PROBLEM

2011-03-05 Thread Logic King
i tried to solve the problem on spoj https://www.spoj.pl/problems/TRT/
the problem is based on DP

i coded the problem as  

#includeiostream
#includealgorithm
#includecstdio
int arr[2000];
int main()
{
int i,l,r,age=1,n,sum=0;
scanf(%d,n);
l=0,r=n-1;
for(i=0;in;i++)
scanf(%d,arr[i]);
for(i=0;in;i++)
{
if(arr[l]=arr[r])
{
sum+=arr[l]*age;
l++;
age++;
}
else
{
sum+=arr[r]*age;
r--;
age++;
}
}
printf(%d\n,sum);
return 0;
}


but i am getting WA on submission
Actually my code fails on some of the test cases like
INPUT-
6
21
31
12
3
4
33



The algorithm i use would give 349 (21*1 + 31*2 + 12*3 + 3*4 + 4*5 + 33*6)
as the answer.

But the correct answer is 389 with sequence of picking as(33, 4, 3, 12, 21,
31).

plz help me improve my algorithm !!

thanking in advance

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] SPOJ PROBLEM

2011-03-05 Thread Arpit Sood
where is dp in your code ? btw, there is a spoj forum, you should search
over there and you will get the required test cases where your code fails.

Cheers!

On Sat, Mar 5, 2011 at 11:45 PM, Logic King crazy.logic.k...@gmail.comwrote:

 i tried to solve the problem on spoj https://www.spoj.pl/problems/TRT/
 the problem is based on DP

 i coded the problem as  

 #includeiostream
 #includealgorithm
 #includecstdio
 int arr[2000];
 int main()
 {
 int i,l,r,age=1,n,sum=0;
 scanf(%d,n);
 l=0,r=n-1;
 for(i=0;in;i++)
 scanf(%d,arr[i]);
 for(i=0;in;i++)
 {
 if(arr[l]=arr[r])
 {
 sum+=arr[l]*age;
 l++;
 age++;
 }
 else
 {
 sum+=arr[r]*age;
 r--;
 age++;
 }
 }
 printf(%d\n,sum);
 return 0;
 }


 but i am getting WA on submission
 Actually my code fails on some of the test cases like
 INPUT-
 6
 21
 31
 12
 3
 4
 33



 The algorithm i use would give 349 (21*1 + 31*2 + 12*3 + 3*4 + 4*5 + 33*6)
 as the answer.

 But the correct answer is 389 with sequence of picking as(33, 4, 3, 12, 21,
 31).

 plz help me improve my algorithm !!

 thanking in advance

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: impliment cin : MS question

2011-03-05 Thread ritu
what question is being discussed here?

On Mar 2, 6:11 pm, Ashish Goel ashg...@gmail.com wrote:
 can it be done without use of a goto? remember that the user can use
 backspace to remove the previous entered string...eg...before pressing
 enter, the user enters abcbsdef so the string is abdef

 How to decide how much buffer is optimum and would use of realloc be a good
 strategy?

 Also, i have a very basic question? Why GOTO is not recommended, i see it
 used like anything in linux kernel..not able to corelate security
 limitations in user mode vers kernel mode.

 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.