首页 > ACM题库 > HDU-杭电 > Hdu 1590 Searching[解题报告] C++
2013
12-12

Hdu 1590 Searching[解题报告] C++

Searching

问题描述 :

"You know what?" Angel said, "There is a love-letter from me embeded on the lawn. And if you can find it, it’s for you~"
"How can I find it on such a big lawn?"
"I will show you a hint: start from that tree which is in center of this lawn, and run directly to (X,Y) point. Please memorize the distance you’v passed. Then turn left with a angle A degree, and go ahead for k times of the length you’v passed in the first step. k is a real number from 0 to 1. When you arrive, repeat to turn left, and run for k times as far as the length of the last step. After many many times, you will reach a place, where I embed my letter…"
Of cause, Gardon wouldn’t follow her hint simply. He just run there directly. Can you do it?

输入:

Input have serveral test cases. Each cases have for real number: X,Y,A,k

输出:

For each case, print the place where the treasure is embed.

样例输入:

1 0 90 0.5
1 0 90 0
1 0 0 0.5

样例输出:

(0.800,0.400)
(1.000,0.000)
(2.000,0.000)


题目主要是向量的运算,用复数类complex比较方便,头文件为#include
向量(x+yi)向左转a角度,大小为原来的k倍,得到向量(x’+y’i)转换公式:
x’=x*cos(a)-y*sin(a);
y’=y*cos(a)+x*sin(a);
=>(x’+y’i)=k*(cos(a)+sin(a)i)*(x+yi);
可以看出成等比数列;
题目就是求它的和的极限。
既:(X,Yi)=(x+yi)/((1,0)-k*(cos(a)+sin(a)i));

#include<cstring>
#include<complex>
#include<cmath>
#define pi acos(-1.0)
using namespace std;
typedef complex<double>Comp;
double x,y,A,k;
int main()
{
    int i,j;
    while(scanf("%lf%lf%lf%lf",&x,&y,&A,&k)!=EOF)
    {
        A=A*pi/180.0;
        Comp a(x,y);
        Comp b(1-k*cos(A),-k*sin(A));
        Comp c=a/b;
       
        printf("(%.3lf,%.3lf)\n",c.real(),c.imag());
    }
    return 0;
} 

 


  1. Often We don’t set up on weblogs, but I would like to condition that this established up really forced me individually to do this! considerably outstanding publish