Rescue The Princess(2013年山東省第4回ACM大学生プログラム設計コンテストA題)
9330 ワード
http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2603&cid=1178
問題の意味は分かったが叩くことができず、チームの中で私より強い大神に聞いてやっと分かった.
これは極座標の作り方です.
View Code
あとこれはFMHで作った三角形の座標で、ベクトルを使うとか、見ていると複雑ですが、実は知識点が分かればわかりやすいので、覚えるのは難しくありません
View Code
問題の意味は分かったが叩くことができず、チームの中で私より強い大神に聞いてやっと分かった.
これは極座標の作り方です.
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)
",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)
",C.x+A.x,C.y+A.y);
38 }
39 return 0;
40 }
View Code