日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

NYOJ 309 BOBSLEDDING(dp)

發(fā)布時(shí)間:2025/3/16 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NYOJ 309 BOBSLEDDING(dp) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

BOBSLEDDING

時(shí)間限制:1000?ms ?|? 內(nèi)存限制:65535?KB 難度:3 描述

Dr.Kong has entered a bobsled competition because he hopes his hefty weight will give his an advantage over the L meter course (2 <= L<= 1000). Dr.Kong will push off the starting line at 1 meter per second, but his speed can change while he rides along the course. Near the middle of every meter Bessie travels, he can change his speed either by using gravity to accelerate by one meter per second or by braking to stay at the same speed or decrease his speed by one meter per second.

Naturally, Dr.Kong must negotiate N (1 <= N <= 500) turns on the way down the hill. Turn i is located T_i ?meters from the course start (1 <= T_i <= L-1), and ?he must be enter the corner meter at ?a peed of at most S_i ?meters per second (1 <= S_i <= 1000). ?Dr.Kong can cross the finish line at any speed he likes.

Help Dr.Kong learn the fastest speed he can attain without exceeding the speed limits on the turns.

Consider this course with the meter markers as integers and the ?turn speed limits in brackets (e.g., '[3]'):

? ? ? ?0 ? ?1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7[3] ? 8 ? 9 ?10 ?11[1] ?12 ? 13[8] ? ?14 ? ? ? ? ? ? ? ? ? ?

(Start) |------------------------------------------------------------------------| ?(Finish) ??

? ? ? ? ? ? ? ? ? ??

Below is a chart of ?Dr.Kong 's speeds at the beginning of each meter length of the course:

Max: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [3] ? ? ? ? ? ? [1] ? ? ?[8]

Mtrs: ? 0 ? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 7 ? 8 ? 9 ?10 ?11 ?12 ? 13 ? 14?

Spd: ? ?1 ? 2 ? 3 ? 4 ? 5 ? 5 ? 4 ? 3 ? 4 ? 3 ? 2 ? 1 ? 2 ? 3 ? ?4

His maximum speed was 5 near the beginning of meter 4.

輸入
There are multi test cases,your program should be terminated by EOF
Line 1: Two space-separated integers: L and N
Lines 2..N+1: Line i+1 describes turn i with two space-separated integers: T_i and S_i
輸出
Line 1: A single integer, representing the maximum speed which Dr.Kong can attain between the start and the finish line, inclusive.
樣例輸入
14 3 7 3 11 1 13 8
樣例輸出
5

題意:一個(gè)人在滑雪的過(guò)程中可以每秒加速1m/s,也可以保持速度不變,還可以每秒減速1m/s。滑道長(zhǎng)L米,有n個(gè)拐角,當(dāng)人滑行到拐角i時(shí),他的速度不能超過(guò)Si。問(wèn)在整個(gè)滑行過(guò)程中,人的最大速度是多少。

分析:假設(shè)人可以一直加速,從前往后遍歷每個(gè)區(qū)間,當(dāng)?shù)侥硞€(gè)拐角時(shí)的速度大于這個(gè)拐角的最大速度時(shí),就向前更新前面的點(diǎn)的最大速度。dp[i]表示在第i米時(shí)可以滑行的最大速度。

#include<stdio.h> #include<string.h> int main() {int L, n, i, dp[1005];while(~scanf("%d%d",&L,&n)){int a, b;memset(dp, 0, sizeof(dp));for(i = 0; i < n; i++){scanf("%d%d",&a,&b);dp[a] = b;}int pos = 1, lim = 1;for(i = 0; i <= L; i++){if(dp[i] == 0) //不是拐角的地方一直加速dp[i] = lim;else{if(dp[i] > dp[i-1])dp[i] = dp[i-1] + 1;else{pos = i; //從當(dāng)前位置向前更新while(dp[pos - 1] - dp[pos] > 1){dp[pos-1] = dp[pos] + 1;pos--;}}}lim = dp[i] + 1;}int mmax = 0;for(i = 0; i <= L; i++)if(dp[i] > mmax)mmax = dp[i];printf("%d\n",mmax);}return 0; }


總結(jié)

以上是生活随笔為你收集整理的NYOJ 309 BOBSLEDDING(dp)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。