hdu 4036 - Rolling Hongshu

來源:互聯網
上載者:User

標籤:style   io   ar   for   sp   問題   on   c   amp   

題目:一個紅薯想去見他的女朋友,他要有一個初始速度,才能翻越高山,問罪最小初速度。

分析:物理題,能量守恒 。

            這道題目也是簡單題目,按照能量守恒進行求解就沒有問題了;

            求出苦馬鈴薯到達起點的速度的最大值,並且求出所有山頂到起點的最大速度,取最大即可;

            求解座標有點麻煩,不過可以直接用比例計算,每次可利用二分最佳化找到對應的最近的山峰。

說明:(2011-09-19 00:49)。

#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>typedef struct _point{    double x,y,v;    double HP;}point;point Poin[ 1005 ];point Tudo[ 1005 ];int search( double X, int H ){    int m,l = 1,h = H;    while ( l < h ) {        m = (l+h+1)>>1;        if ( Poin[ m ].x > X )            h = m-1;        else l = m;    }    return h;}int main(){    int T,N,M,W;    scanf("%d",&T);    for ( int t = 1 ; t <= T ; ++ t ) {                scanf("%d%d%d",&N,&M,&W);        for ( int i = 1 ; i <= N ; ++ i )            scanf("%lf%lf",&Poin[ i ].x,&Poin[ i ].y);        for ( int i = 1 ; i <= M ; ++ i )            scanf("%lf%lf%d",&Tudo[ i ].x,&Tudo[ i ].v,&W);                    for ( int i = 1 ; i <= M ; ++ i ) {            int s = search( Tudo[ i ].x, N );                        if ( Tudo[ i ].x == Poin[ s ].x )                Tudo[ i ].y = Poin[ s ].y;            else                Tudo[ i ].y = Poin[ s ].y + (Poin[ s+1 ].y-Poin[ s ].y)/(Poin[ s+1 ].x-Poin[ s ].x)*(Tudo[ i ].x-Poin[ s ].x);                            Tudo[ i ].HP = 40.0*(Tudo[ i ].y-Poin[ 1 ].y) + Tudo[ i ].v*Tudo[ i ].v;        }                double Max = 0;        for ( int i = 1 ; i <= M ; ++ i )            if ( Max < Tudo[ i ].HP )                 Max = Tudo[ i ].HP;                        for ( int i = 2 ; i <= N ; ++ i ) {            double HP = 40.0*(Poin[ i ].y-Poin[ 1 ].y);            if ( Max < HP ) Max = HP;        }                printf("Case %d: %.2lf\n",t,sqrt(Max));    }    return 0;}

hdu 4036 - Rolling Hongshu

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.