Title Address: http://acm.hdu.edu.cn/showproblem.php?pid=3365
Idea: Take a[0] as the origin, construct vector a[i]-a[0]. First rotate (note the direction of rotation), then stretch, and finally pan to the end.
#include <cstdio> #include <cmath> #include <cstring> #include <iostream> #include < Algorithm> #define Debuusing namespace std;const double eps=1e-7;const int maxn=1e4+50;const double Pi=acos (-1.0); struct vector{double x, y; Vector (Double x=0,double y=0): X (x), Y (y) {}};int n; Vector A[maxn],b[5]; Vector operator + (const vector &a,const vector &b) {return vector (A.X+B.X,A.Y+B.Y);} Vector operator-(const vector &a,const vector &b) {return vector (A.X-B.X,A.Y-B.Y);} Vector operator * (const vector &a,const double &p) {return vector (a.x*p,a.y*p);} int dcmp (double x) {if (Fabs (x) <eps) return 0; else return x<0?-1:1;} Double Dot (const vector &a,const vector &b) {return a.x*b.x+a.y*b.y;} Double Length (const Vector &a) {return sqrt (Dot (a,a));} Double Cross (const vector &a,const vector &b) {return a.x*b.y-a.y*b.x;} Vector Rotate (const vector &a,double rad) {return Vector (A.x*cos (RAD)-a.y*sin (RAD), A. X*sin (RAD) +a.y*cos (RAD));} int main () {#ifdef debug Freopen ("In.in", "R", stdin), #endif//debug int t,cas=0; scanf ("%d", &t); while (t--) {scanf ("%d", &n); for (int i=0; i<n; i++) scanf ("%lf%lf", &a[i].x,&a[i].y); for (int i=0; i<2; i++) scanf ("%lf%lf", &b[i].x,&b[i].y); Vector TMP1,TMP2; TMP1=A[1]-A[0]; TMP2=B[1]-B[0]; Double Len=length (TMP2)/length (TMP1); Double Rad=acos (Dot (TMP1,TMP2)/(Length (TMP1) *length (TMP2))); cout<<rad<<endl; if (Cross (TMP1,TMP2) <eps) Rad=2.0*pi-rad; cout<< "Rad" <<rad<<endl; for (int i=2; i<n; i++) {a[i]=a[i]-a[0]; cout<< "Flag" <<A[i].x<< "" "<<A[i].y<<endl; A[i]=rotate (A[i],rad); cout<<a[i].x<< "" <<A[i].y<<endl; A[i]=a[i]*len; A[I]=A[I]+B[0]; } printf ("Case%d:\n", ++cas); printf ("%.2f%.2f\n", b[0].x,b[0].y); printf ("%.2f%.2f\n", b[1].x,b[1].y); for (int i=2; i<n; i++) printf ("%.2f%.2f\n", a[i].x,a[i].y); } return 0;}
Hdu 3365 New Ground (computational geometry)