Posts

Showing posts from August, 2017

Spoj CLOPPAIR Solution

This is the solution for spoj Closest Point Pair  #include<bits/stdc++.h>  using namespace std;  #define mn 9999999999.9  struct point  {       long double x,y;       int index;  };  point makepoint(double a,double b,int i) {       point temp;     temp.x=a;temp.y=b;temp.index=i;       return temp; }        double dist(point p1,point p2)  {      return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y));  }  bool compareX(point a,point b) {     return a.x < b.x; } bool compareY(point a,point b) {     return a.y < b.y; }  int indexa,indexb; double ans=999999999; double bruteforce(point p[],int n) {   double d=mn;  for( int i=0;i<n;i++)  {    for(int j=i+1;j<n;j...

Spoj NDIV Solution

                            This is the solution for spoj n-divisors        #include<bits/stdc++.h>     using namespace std;   int mx=32000;        vector<int> prime;     void sieve()  {    int isprime[mx],i,j;        for(i=0;i<=mx;i++)        isprime[i]=1;         isprime[0]=0;        isprime[1]=0;       for(i=4;i<=mx;i+=2)       isprime[i]=0;   for(i=3;i*i<=mx;i+=2)   {      if(isprime[i])      {        for(j=i*i;j<=mx;j+=i*2)             isprime[j]=0;      }   }     for(i=2;i<=mx;i++)    {  ...