Rescue The Princess(2013年山东省第四届ACM大学生程序设计竞赛A题)

http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2603&cid=1178

明白了题的题意但是不会敲,问了队里比我厉害的大神才懂

这个是极坐标的做法

 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<string.h>
 4 #define PI acos(-1.0)
 5 int main()
 6 {
 7     int n;
 8     double x1,x2,x3,y1,y2,y3,l;
 9     scanf("%d",&n);
10     for(int i = 1 ; i <= n ; i++)
11     {
12         scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
13         double du = atan2((y2-y1),(x2-x1));
14         l = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
15         x3 = x1 + l*cos(du+PI/3);
16         y3 = y1 + l*sin(du+PI/3);
17         printf("(%.2lf,%.2lf)\n",x3,y3);
18     }
19     return 0;
20 }
View Code

还有这个是FMH做的三角形坐标,用的向量什么的,看着有些复杂,不过其实知识点了解了之后就好懂了,就是要记住就不太难了

 1 #include<cstdio>
 2 //#include<cstring>
 3 //#include<algorithm>
 4 //#include<iostream>
 5 #include<cmath>
 6 //#include<complex>
 7 using namespace std;
 8 #define PI 3.1415926
 9 struct Point
10 {
11     double x,y;
12     Point(double x=0,double y=0):x(x),y(y){}
13 };
14 
15 typedef Point Vector;
16 Vector Rotate(Vector A,double rad){
17    return Vector (A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
18 }//旋转,rad是弧度
19 
20 //double Cross(Vector A,Vector B){ return A.x*B.y-A.y*B.x;}//叉积
21 
22 Vector operator - (Point A,Point B) {return Vector(A.x-B.x,A.y-B.y);}
23 //Vector operator + (Vector A,Vector B) {return Vector(A.x+B.x,A.y-B.y);}
24 //Vector operator * (Vector A,double p) {return Vector(A.x*p,A.y*p);}
25 
26 int main()
27 {
28     int t;
29     Point A,B,D;
30     Vector C;
31     scanf("%d",&t);
32     while(t--)
33     {
34         scanf("%lf %lf %lf%lf",&A.x,&A.y,&B.x,&B.y);
35         Vector v1=B-A;//AB向量
36         C=Rotate(v1,PI/3);//旋转之后的向量
37         printf("(%.2lf,%.2lf)\n",C.x+A.x,C.y+A.y);
38     }
39     return 0;
40 }
View Code
原文地址:https://www.cnblogs.com/luyingfeng/p/3136792.html