Help me Debug WTBTR

debug
easy

#1

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.


#2

you need to sort x and y axis saperately…


#3

Just add the line :- cout.precision(30)
before printing the answer
The link to the modified code :- https://ideone.com/nZ2J2f


#4

That was it. I feel silly getting the logic right and then not printing the solution correctly


#5

Take care the next time.


#6

here is my solution

https://www.codechef.com/viewsolution/24272229


#7

I think setting precision to 30 is not a good idea just use this instead

cout << fixed;


#8

Why is it better than setting precision to 30 @samarthtandon? Also I am sorting along the x and y co-ordinates separately.


#9

see my earlier reply


#10

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.


#11

use fast i/o in your code


#12

samarthtandon please elaborate


#13

add these lines…

ios::sync_with_stdio(0); cout.tie(0); cin.tie(0);


#14

Fast i/o won’t work as his code gives WA for most of the test-cases and not TLE :frowning:


#15

The min() function is only used to compare 2-integers, don’t use it, compare the numbers by yourself , using greater than condition :slight_smile:


#16

I don’t know but he said he is getting TLE
??


#17

thnx samarth! it’s working now


#18

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 :slight_smile: