### kazama460's blog

By kazama460, history, 8 months ago, ,
#include<bits/stdc++.h>
using namespace std;

int main()
{
float x1,x2,y1,y2,x3,y3,x4,y4,ansx,ansy;

while(cin>>x1>>y1)
{
cin>>x2>>y2>>x3>>y3>>x4>>y4;

if(x1==x3 && y1==y3)
{
ansx = x2-x1+x4;
ansy = y2-y1+y4;
}

else
if(x2==x3 && y2==y3)
{
ansx = x1-x2+x4;
ansy = y1-y2+y4;
}
else
if(x1==x4 && y1==y4)
{
ansx = x2-x1+x3;
ansy = y2-y1+y3;
}

else
{
ansx = x1-x2+x3;
ansy = y1-y2+y3;
}
printf("%.3lf %.3lf\n", ansx, ansy);
}
}


i dont know whats wrong with code , getting wrong answer. if anyone can point out some problem in the code. thank you in advance. Link to problem

 » 8 months ago, # |   0 Definitely your code is incorrect for following reasons: First, three if conditions mean the two coordinates are collinear (e.g x1==x4 && y1==y4 means two points (x1, y1) && (x4, y4) are collinear which is not possible for a ||gm.). Second, Every time only last condition will execute giving x1-x2+x3 & y1-y2+y3. Check and report to me if you do not get this answer every time. Also if you get incorrect ans, use printf to know which part of 'if' is executing, and check if it meets the required condition.
•  » » 8 months ago, # ^ |   0 there was only problem in the precision , the idea is perfect , read the problem statement carefully , then you find why my code is correct.
 » 8 months ago, # |   0 your idea is definitely correct, I suspect this might be a precision issue, I don't have a uVa account, so I can't test it out, but can you try changing your float to double or long double?