nitin1 15 Master Poster

what is this ? is there any relevenace to the topic ?

nitin1 15 Master Poster

100% correct! i also remeber that i have read it somehere, please deceptikon throw some light on this also which somjit{} is saying thanks.

nitin1 15 Master Poster

actually , I am working on a project and i need to sort the co-ordinates in the increasing y value.

input: 1 2
3 4
5 6
6 6
7 8
4 5

like this, and i need to sort them in the increasing y value.

my approach: i think that i should store them in a struture having memebers x and y and sort them. but problem is i wana do this in nlogn by using quick sort or merge sort. and for quick making the code, i wana use the qsort() function already defined in the C. this function needs a compare() and array which we nned to sort. but problem is that i want to sort the array of structures on the basis of its one member which is y in this case. can you help me a little bit? thanks in advance.

nitin1 15 Master Poster

I know professionals never get angry in thier job and working area. you have actually thought me the prfoessionlism and from 20 till my life will increase this professionalism in myself. no anger, no love, no excessive kissing,no hate ;) thanks alot ;)

nitin1 15 Master Poster

@pytony Can you elaborate a more ? thanks

nitin1 15 Master Poster

firstly fabs is the function which return absolute value and number is the number which i wana check. right ? so you are checking that difference betweem them should be less than 0.0001 ? will it give the correct answer in every case ? confirmed ? can there be any case in which it can give error ?

nitin1 15 Master Poster

awesome thinking! hats off man! i am thinking on this now! ;) that's a cool idea where i can learn alot and alot and without any limit! as james sir has said "sky is the limit!" ;)

nitin1 15 Master Poster

the knowledge which you guys are providing is incredible. hey! what exactly i can do in github ? means what specific use github has ? just uploading your project files ? thanks

nitin1 15 Master Poster
#include <stdio.h> 
#include <math.h> 

int main(void) 

{ 
int number; 
double result; 

printf ("\n Introduce an integer: "); 

scanf ("%i", &number); 

result= sqrt (number); 

if ((result * result)== number) 
printf ("\n The integer HAS a perfect square \n\n"); 

else 
printf ("\n The integer DOES NOT HAVE a perfect square \n\n"); 

}

although, this code gives me correct output for values, but i wana ask is it the right way to check that a number is a perfect square ? as i am taking result as double which always a approximate value so multiplying this (result*result) will give me the correct output ? thanks in advance.

nitin1 15 Master Poster

oops! first time you got angry! :( sorry! no need of any other language. C is best and english is best! :( okies! o(mn) finally ;)

nitin1 15 Master Poster

so when i say that range is fix like the INT_MAX, then can't i say that it is O(n) ?

nitin1 15 Master Poster

sir, then m is also a constant. like if int max is there, then m is 10 here. so can't we take it as a constant ?

nitin1 15 Master Poster

if his problem is solved and if he didnit mark the thread solved, then ? :-o

nitin1 15 Master Poster

how much gcd is taking in each iteration ? O(n) is the time taken to travserse the array length. then where is the gcd time included in this complexity ? is it a constant according to you ?

nitin1 15 Master Poster

i am traversing full length of array and for each element i am calling gcd() also. So what time gcd is taking in this procedure of finding lcm ? o(n) is the travsering array length. okay? than in each iteration how much gcd takes ? please clearify, thanks

nitin1 15 Master Poster

i mean when our solved threads increases, then on what basis they are increased because more of the threads are not marked solved. thanks

nitin1 15 Master Poster

it is a number in octal form as it has 0 in the starting. So it is 000 000 000 000 001 001, so this is nine as you well know ;) thanks

nitin1 15 Master Poster

thanks you ! but i have implemented for 2 lines. but i am not getting for n line segments. thanks

nitin1 15 Master Poster

hey, i want to do a question in which i am given n line segments and i want to find the number of intersection of them. Can anyone tell me the most efficient way i can do it ? I have got some links on google and also from books but i am not getting it. I am not asking for code or something like that and neither it is my homework. So please help me if you can. thanks

nitin1 15 Master Poster

okay! i got that i need to read k elements from the set which make it divisible by 9. okay. but i need efficient one. why are you repeating that this is an unintersting problem ? and can you provide me the way to solve this question in the exact way ?

nitin1 15 Master Poster

then how to do that ? i mean if i want current time then what i need to do ?

nitin1 15 Master Poster

no, How exactly you are dealing with the pronlem i have asked you ? I mean Can't i sort the strings just by using qsort() function ? if yes, then what type of array will i send in the function ? and if no, then how exaclty you are storing the string so as to sort them and then make LCP array. I hope you are corerctly getting what i am trying to ask you. are you getting what exactly i am trying to ask ? just read the first post once, and let me tell u what exactly i want.

I input a string. okay ? then i have to make a LCP array(which i know) and suffix array(it is a part in making full siffix array algorithm) okay ? now, when i input a string, then i need to have a sorted version of all suffices of a string which i input as given in the first post of banana. okay ?

My approach: i wana use qsort() function defined in C already so as the sort all the sub-strings which i have got after cutting the big string like i have shown in the first post. okay ? now, my question is how to store and then sort the sub-string which i have got above after cutting, and after sorting i will make a LCP array which i know how to make that.

Basic question: this question is that find all the possible different sub-string in the …

nitin1 15 Master Poster

clock() returns double and and number of ticks and you should divide it with ticks_per_second so as to get the time. thanks

nitin1 15 Master Poster

okay! after converting it then ? what is the next step it this ?

nitin1 15 Master Poster

it has given that you have to k elements. so what exactly i can follow, that what i am not getting. i know greedy can work here, but how is it implementing. what have you thought ?

and the question you have asked in last line, i am thinking upon it. thanks

nitin1 15 Master Poster

hey deceptikon is it using logn time to evaluate a fibo numbers. i have traced it, but i may be wrong so that's why confirming with you ?

i don't know which GOOGLE you use :p i also search from that google.com from where you search, but i didn't get these things :-) and from where i can read the logic which is used in this ? like the terms they are using and all the logic behind this. this is an awesome and fantastic way to implement that. too easy to read! thanks please tell :)

nitin1 15 Master Poster
#include<stdio.h>
#define MOD 100000009

#define REP(i, n) for(i = 0; i < n; ++i)

void mul(int a[2][2],int b[2][2])
{
    int i,j,k;
    int c[2][2];
    for(i=0;i<2;i++)
    {
         for(j=0;j<2;j++)
         {
                         c[i][j]=0;
                         for(k=0;k<2;k++)
                         {
                                         c[i][j]+=(a[i][k]*b[k][j]);

                         }
         }
    }                                              // matrix multiply

    i=0;j=0;

    REP(i,2)
    REP(j,2)
    b[i][j]=c[i][j];    // copying the value in back to b[][]

    return;
}

void calc(int a[2][2],int b[2][2],int p)
{
     int i,j,k;

      if(p==1)
      {
              REP(i,2)
              REP(j,2)
              b[i][j]=a[i][j];  
              return;       
      }

      if(p%2==0)
      {
              calc(a,b,p/2);
              mul(b,b);
      }
      else
      {
           calc(a,b,p/2);
             mul(b,b);
             mul(b,a);
      }

      return;
}

int main()
{
      int t[2][2]={
                     {0,1},
                     {1,1}
                };       

      int f[2][1]={
                   {1},
                   {1}             
                };
      int n=3;
      int i,j;
      int b[2][2];

      calc(t,b,n-1);


               REP(i,2) 
               REP(j,2)
      printf("%d ",b[i][j]);        

    /*  int g[2][1]={
                     {b[0][0]*f[0][0]+b[0][1]*f[1][0]},
                     {b[1][0]*f[0][0]+b[1][1]*f[1][0]}
                };      
      */
      getch();

    return 0;
}

this is a code for finding nth fibo number in logn time. I have multiplied a matrix T n-1 times. But the problem with code is that it is same output for n=3 and n=4 both. I am not able to figure out the error. thanks if you can help me in this.

Answer for n=3 and n=4 which it is giving: 1 1 1 2 which is wrong. So can you figure out where can be the problem ? And it is also giving wrong output some other cases also. I think there is some logical problem.thanks in advance.

nitin1 15 Master Poster

how are you thinking to do it ? divisible by 9 means sum of digits is divisible by 9. okay ? then how are you thinking to do that ??

nitin1 15 Master Poster

that's good! that's why he was able to delete his one post in my thread. ;) wow!

nitin1 15 Master Poster

@zeroliken the same thing i was expecting from waltP. that's set. thanks. ;) and how thread can be deleted ? :-o

nitin1 15 Master Poster

isn't there any way that you can know who is downvoting or upvoting your posts ? if yes, then how can i know that ? thanks ;) may be this feature can be added. ;)

nitin1 15 Master Poster

it's not the way of answering any question waltP. if anyone is asking, then rather than saying "it's none of your buisness" OR "you will not get it" OR "it's not for you", something like this MUST not be there while you are in a fourmn where you need to share info. it will be good for you and all if you share every possible thing you can. thanks anyways for your valuable replies.

nitin1 15 Master Poster

http://www.spoj.pl/problems/FP/

here is the link. Can anyone please give me the hint only that how greedy approach is following in this question ? It's strange to see how greedy is there in this question. just the hint of this. no code, nothing! thanks.

nitin1 15 Master Poster
#include<stdio.h>

int gcd(int a,int b)
{
    if(b>a)
    return gcd(b,a);

    if(b==0)
    return a;

    return gcd(b,a%b);
}

int lcm(int a,int b)
{
    int k=gcd(a,b);

    a/=k;

    return a*b;
}

int main()
{
    int a[]={5,10,15,20,40};
    int n=sizeof a/sizeof a[0];
    int n1=n;
    int k=a[0];

    n--;

    while(n>=1)
    {
           k=lcm(k,a[n--]);
    }

    printf("LCM of N numbers is: %d\n",k);

    return 0;
}

i have calculates the time complexity as O(nlogn). Am i right ? please verify.
And can anyone improve this any more ? thanks.

m4ster_r0shi commented: Yeap, you got the idea. +6
nitin1 15 Master Poster

no, like in the string banana, i am thinking that i will make a 2-D array and in each row i will store it's one sub-string and then sort. got it ? but i am thinking that if i do that, then 2-D array will go out of bounds. so was asking for your help that how are you thinking this problem ? and which Ds you are using to store the strings before sorting them ? thanks

@first person string is of max length:1,00,000. problem statement is that i need to find the different sub-string in a string. like banana here. and i am using suffix array to do that. and suffix array need sorting of its sub-strings which i have prvided in the first post. got it ? now, my question is that how to store those strings and then i need to sort then also. i so coding in pure C. can you help a little bit ? thanks

nitin1 15 Master Poster

when there is a new post in our threads, then we need to refresh. Can you(all admins) do something so that we shouldn't do this thing or is it neccessay everytime ? thanks. it's just a suggestion of a problem whioch i face generally. still, it is okay for me :-D

nitin1 15 Master Poster

Computer Science is not much active. sorry to say this thing again! but whenever i post it, no body is there to reply. okay! i will post it and will hope a better reponse from you all guys. thanks

nitin1 15 Master Poster

what's going on ? only walt posts are here. with whom is he talking or say, discussing ? thanks ;)

nitin1 15 Master Poster

okay! sory for that ! will not do this type of mistake in future!

@ L7Sqr Can you tell me what exactly that base-N problem you mean by ? please explain a little bit. I am eager to know a second approch of this question. The code i have provided is done by me just in 3 minutes after reading problem. way which you are telling is different from my approach ?

Secondly, can you tell what is base in this and please specify how you are relating this problem to base-N ? thanks ;)

nitin1 15 Master Poster

@npcomplete this is the most common mistake which you have done. This thing is valid for the 2 numbers and if you want to extend it then here goes:

lcm(a,b,c,d....)= gcd(a,b,c,d....)* (a/gcd(a,b,c,d.....))* (b/gcd(a,b,c,d.....)) * (c/gcd(a,b,c,d....)).......

try with 5,10,15 and your algo will not work and then do it with mine, it will work for every set of numbers.

@waltP you are talking about which algorithm if you don't want to make use of gcd here? please throw a little bit light on it.

@m4ster rOshi Can you please explian a little bit the solution which you are providing here ? please explain a little bit , just i need a jist to understand it. thanks in advance to all of you. ;)

nitin1 15 Master Poster

it is the most easy problem i have seen in my coding carrier. here goes the solution ;'

#include<stdio.h>

int main()
{
    int a,k,n;

    scanf("%d%d%d",&a,&n,&k);

    while(k--)
    {
           printf("%d ",a%(n+1));
           a/=(n+1);
    }

    return 0;
}

feel free to ask doubts! thanks

Ezzaral commented: Handing someone a code solution doesn't help them learn. -3
nitin1 15 Master Poster

hi, Can anyone suggest me the approach for finding the lcm of the n numbers?

my approach: find the max of the n numbers and start dividing it by all numbers , if all are dividing it then print it, else take next multiple of the max number and repaet the division process. but i think this is too slow. i want better than this. So any one has better idea bout this ?

nitin1 15 Master Poster

can u elborate more ? i am not going to use 2-D array here

nitin1 15 Master Poster

purple color is damn awesome dani ;) seriously, this forumn presentation is awesome as compared to any other CS forumns i have ever met. if this color was chosen by you, then hats off to your colour selection. (it seems you are very good at selecting dresses(kidding) ;) )

Dani commented: Thanks +0
nitin1 15 Master Poster

yeah... u have approached the nice person now

nitin1 15 Master Poster

hey! what is that in line 5 ? i didn't get anything in that line sorry to say. please clearify

nitin1 15 Master Poster

yes! mircosoft seems to publicize itself by giving the colour of daniweb to its own page ;) i always says "dani and daniweb is awesome!" :-)

nitin1 15 Master Poster

@taywin yes, i have read the link very nicely before your post. i have read around 10 articles on it. but i wana ask that should i use a 2-D array for storing this types of different strings which i think is not the solution. Can you suggest me any tricky way to do this ? like something related to pointer? (because many strings problems solves with pointer, but in this case i am not getting how!) thanks

nitin1 15 Master Poster

deceptikon, please throw more light on this. how fgets() is more better than what npcpmplete has said. i am eager to know that. thanks

nitin1 15 Master Poster
#include<stdio.h>

int main()
{
    char a[60][60],b[60][60],i=0,n1,m1,n2,m2;
    int x,y;
    int j=0;
    char c;
    int p=-1,q=-1,f=-1,g=-1;
    scanf("%d%d",&n1,&m1);



    for(i=1;i<=n1;i++)
    scanf(" %s",a[i]);

    scanf("%d%d",&n2,&m2);




    for(i=1;i<=n2;i++)
    scanf(" %s",b[i]);

    for(i=1;i<=n1;i++)
    {
           for(j=1;j<=m1;j++)
           {
                   if(a[i][j]=='1')
                   {
                         p=i;
                         q=j;  
                         break;                   
                   }

           }
            if(p>0 || q>0)
                   break;
    }


    for(i=1;i<=n2;i++)
    {
           for(j=1;j<=m2;j++)
           {
                   if(b[i][j]=='1')
                   {
                         f=i;
                         g=j;
                         break;                     
                   }
           }

            if(g!=-1 || f!=-1)
                   break;
    }

    printf("%d %d\n",f-p,g-q);


    return 0;
}

this is a code snippet. it is not taking i/p in scanf(%s) lines in the code. it is exiting after taking 2 strings only. but not for n1 and n2. please tell ehat is problem ?