[algogeeks] Re: SPOJ problem code:MAJOR

2011-03-16 Thread .bashrc
its a simple hashing problem i suppose.Beware there are some traps though.It took me 9 submissions to get it fixed. Just remember there are 1000 numbers so the array would be a[1001] -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post

Re: [algogeeks] Re: SPOJ problem code:MAJOR

2011-02-15 Thread Balaji Ramani
@Akshata I managed to get AC with majority algorithm. suggestions: 1) You can try to read input and find candidate in same loop 2) Use scanf and printf Thanks, Balaji. On Tue, Feb 15, 2011 at 4:30 PM, jai gupta wrote: > #include > #include > #include > void work() { > int n,max,maxpos,x,

Re: [algogeeks] Re: SPOJ problem code:MAJOR

2011-02-15 Thread jai gupta
#include #include #include void work() { int n,max,maxpos,x,i; scanf("%d",&n); int *arr=(int*) malloc(sizeof(int)*2005); memset(arr,0,2005); max=maxpos=0; for(i=0;imax) { max=arr[x+1000]; maxpos=x; } } if(max>n/2) print

[algogeeks] Re: SPOJ problem code:MAJOR

2011-02-14 Thread NEERAJ ARORA
I simply used arrays to count the frequency of each numberMy accepted solution is: #include int main() { int t,n,i,p,x,chk,k; int pos[1000]; int neg[1000]; int nos[100]; scanf("%d",&t); while(t--) { chk=0;

[algogeeks] Re: SPOJ problem code:MAJOR

2011-02-14 Thread sankalp srivastava
A few problems with your code : 1)Very Unclear (sorry !):- Either use a camelCase like java or use the c++ underscores style .Paste ur code on pastebin etc. 2)Too many loops :- It is O(n) , but perhaps O(4000*n) , much worse than O(n^2) in this case. 3)The problem is based on majority element con

Re: [algogeeks] Re: SPOJ problem code:MAJOR

2011-02-14 Thread Terence
Try scanf/printf instead of cin/cout. For huge data set, the IO time matters. On 2011-2-14 20:09, Akshata Sharma wrote: link to problem: http://www.spoj.pl/problems/MAJOR/ On Feb 14, 5:03 pm, Akshata Sharma wrote: I am trying to submit my solution but its giving TLE. My implemetation is O(n).

Re: [algogeeks] Re: SPOJ problem code:MAJOR

2011-02-14 Thread sunny agrawal
try replacing cin, cout by printf,scanf On Mon, Feb 14, 2011 at 5:39 PM, Akshata Sharma wrote: > link to problem: http://www.spoj.pl/problems/MAJOR/ > > On Feb 14, 5:03 pm, Akshata Sharma wrote: > > I am trying to submit my solution but its giving TLE. My implemetation is > > O(n).. and i am not

[algogeeks] Re: SPOJ problem code:MAJOR

2011-02-14 Thread Akshata Sharma
link to problem: http://www.spoj.pl/problems/MAJOR/ On Feb 14, 5:03 pm, Akshata Sharma wrote: > I am trying to submit my solution but its giving TLE. My implemetation is > O(n).. and i am not able to think a faster algo than this for the problem. > The problem is based on finding the majority ele