There is some small mistake in my code. Help will be appreciated.
I have first applied the transformation (x,y) goes to (x-y,x+y) . This rotates the plane anticlockwise by 45 deg. This also scales the grid so that the multiplication by sqrt(2) is not needed at the end.
Then I sort first using the first coordinate and find the minimum difference and do the same for the second coordinate. Half of the minimum of these two is the answer.
you need to sort x and y axis saperately…
Just add the line :- cout.precision(30)
before printing the answer
The link to the modified code :- nZ2J2f - Online C++0x Compiler & Debugging Tool - Ideone.com
That was it. I feel silly getting the logic right and then not printing the solution correctly
Take care the next time.
I think setting precision to 30 is not a good idea just use this instead
cout << fixed;
Why is it better than setting precision to 30 @samarthtandon? Also I am sorting along the x and y co-ordinates separately.
see my earlier reply
I am also using the same approach but why does it show time limit exceeded when i am just using a sorting.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int tc;
cin>>tc;
//int flag=0;
while(tc–)
{
int n;
cin>>n;
//node arr[n];
long double d1[n],d2[n];
for(int i=0;i<n;i++)
{
long double x;
long double y;
cin>>x>>y;
d1[i]=y-x;
d2[i]=y+x;
}
sort(d1,d1+n);
sort(d2,d2+n);
long double min1=d1[1]-d1[0];
long double min2=d2[1]-d2[0];
for(int i=0;i<n-1;i++)
{
if(d1[i+1]-d1[i]<min1)min1=d1[i+1]-d1[i];
if(d2[i+1]-d2[i]<min2)min2=d2[i+1]-d2[i];
}
min1=min(min1,min2)/2;
cout.precision(30);
cout<<min1<<endl;
}
}
Help will be highly appreciated.
use fast i/o in your code
samarthtandon please elaborate
add these lines…
ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);
Fast i/o won’t work as his code gives WA for most of the test-cases and not TLE
The min() function is only used to compare 2-integers, don’t use it, compare the numbers by yourself , using greater than condition
I don’t know but he said he is getting TLE
??
thnx samarth! it’s working now
Oops, I saw your code which had WA in big test-cases,in actual-contest, so thought you should get AC in those cases first, then remove TLE, ALWAYS USE FASTI IO