https://www.hackerrank.com/challenges/find-point/problem
if point P(px,py) is rotated around point Q(qx,qy) by 180 degrees then it reaches a point R(rx,ry)
hence qQ would be mid point between P and R
so (px+rx)/2 = qx and (py+ry)/2 = qy
from the above equatiions, px,py,qx and qy are given we need to find rx,ry
hence rx = 2*qx-px and ry = 2*qy-py
#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int px,py,qx,qy,rx,ry;
scanf("%d%d%d%d",&px,&py,&qx,&qy);
rx=2*qx-px;
ry=2*qy-py;
printf("%d %d\n",rx,ry);
}
return 0;
}
if point P(px,py) is rotated around point Q(qx,qy) by 180 degrees then it reaches a point R(rx,ry)
hence qQ would be mid point between P and R
so (px+rx)/2 = qx and (py+ry)/2 = qy
from the above equatiions, px,py,qx and qy are given we need to find rx,ry
hence rx = 2*qx-px and ry = 2*qy-py
#include <stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int px,py,qx,qy,rx,ry;
scanf("%d%d%d%d",&px,&py,&qx,&qy);
rx=2*qx-px;
ry=2*qy-py;
printf("%d %d\n",rx,ry);
}
return 0;
}
No comments:
Post a Comment