CSU1549-Navigition Problem-几何简单题

P: Navigition Problem

Description

Navigation is a field of study that focuses on the process of monitoring and controlling the movement of a craft or vehicle from one place to another. The field of navigation includes four general categories: land navigation, marine navigation, aeronautic navigation, and space navigation. (From Wikipedia)
Recently, slowalker encountered a problem in the project development of Navigition APP. In order to provide users with accurate navigation service , the Navigation APP should re-initiate geographic location after the user walked DIST meters. Well, here comes the problem. Given the Road Information which could be abstracted as N segments in two-dimensional space and the distance DIST, your task is to calculate all the postion where the Navigition APP should re-initiate geographic location.

Input

The input file contains multiple test cases.
For each test case,the first line contains an interger N and a real number DIST. The following N+1 lines describe the road information.
You should proceed to the end of file.

Hint:
1 <= N <= 1000
0 < DIST < 10,000

Output

For each the case, your program will output all the positions where the Navigition APP should re-initiate geographic location. Output “No Such Points.” if there is no such postion.

Sample Input

2 0.50
0.00 0.00
1.00 0.00
1.00 1.00

Sample Output

0.50,0.00
1.00,0.00
1.00,0.50
1.00,1.00

这个几何题明明比入门的水来着。。。。
就是给你n+1个点构成n条首位连接的线段,问你每次沿着这个走d的距离,到哪里,如果d已经超过线段总长就输出No Such Points.
我因为No Such Points.没打对WA3发,宛如一个ZZ……

#include <bits/stdc++.h>
#define N 1010
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
struct Point{
    double x,y;
}p[N];
double sum[N],len[N];
inline double dis(Point &a,Point &b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
//  ios::sync_with_stdio(false);
    int n;
    double d,tot,cur,x,y,k;
    p[0].x=p[0].y=0;
    while(~scanf("%d%lf",&n,&d)){
        tot=0;
        sum[0]=0;
        for(int i=0;i<n+1;++i){
            cin>>p[i].x>>p[i].y;
            if(i){
                len[i]=dis(p[i],p[i-1]);
                tot+=len[i];
                sum[i]=sum[i-1]+len[i];
            }
        }
//      for(int i=0;i<n+1;++i){
//          cout<<len[i]<<' '<<sum[i]<<endl;
//      }
        if(tot<d){
            cout<<"No Such Points."<<endl;
        }else{
            cur=0;
            for(int i=0;i<=n;){
//              cout<<i<<' '<<cur<<endl; 
                if(cur+d<=sum[i]){
                    double l=cur+d-(i?sum[i-1]:0);
                    double x1=p[i-1].x,y1=p[i-1].y,x2=p[i].x,y2=p[i].y;
                    if(x1!=x2){
                        k=(y1-y2)/(x1-x2);
                        if(x2>x1){
                            x=x1+sqrt((l*l)/(1+k*k));
                            y=k*(x-x1)+y1;
                        }else{
                            x=x1-sqrt((l*l)/(1+k*k));
                            y=k*(x-x1)+y1;
                        }
                    }else{
                        x=x1;
                        if(y2>y1){
                            y=y1+l;
                        }else{
                            y=y1-l;
                        }
                    }
                    printf("%.2f,%.2f\n",x,y);
                    cur=cur+d;
                }else{ 
                    ++i;
                }
            }
        }
    }
    return 0;
}
/**********************************************************************
    Problem: 1549
    User: CSUzick
    Language: C++
    Result: AC
    Time:4 ms
    Memory:1756 kb
**********************************************************************/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值