POJ-2017 Speed Limit-行駛公里數
Speed Limit
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 18170 | Accepted: 12745 |
Description
Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don't know how many miles they have driven. Fortunately, Bill has a working stopwatch, so they can record their speed and the total time they have driven. Unfortunately, their
record keeping strategy is a little odd, so they need help computing the total distance driven. You are to write a program to do this computation.
For example, if their log shows
this means they drove 2 hours at 20 miles per hour, then 6-2=4 hours at 30 miles per hour, then 7-6=1 hour at 10 miles per hour. The distance driven is then (2)(20) + (4)(30) + (1)(10) = 40 + 120 + 10 = 170 miles. Note that the total elapsed time is always since the beginning of the trip, not since the previous entry in their log.
For example, if their log shows
Speed in miles perhour Total elapsed time in hours 20 2 30 6 10 7
this means they drove 2 hours at 20 miles per hour, then 6-2=4 hours at 30 miles per hour, then 7-6=1 hour at 10 miles per hour. The distance driven is then (2)(20) + (4)(30) + (1)(10) = 40 + 120 + 10 = 170 miles. Note that the total elapsed time is always since the beginning of the trip, not since the previous entry in their log.
Input
The input consists of one or more data sets. Each set starts with a line containing an integer n, 1 <= n <= 10, followed by n pairs of values, one pair per line. The first value in a pair, s, is the speed in miles per hour and the second value, t, is the total
elapsed time. Both s and t are integers, 1 <= s <= 90 and 1 <= t <= 12. The values for t are always in strictly increasing order. A value of -1 for n signals the end of the input.
Output
For each input set, print the distance driven, followed by a space, followed by the word "miles"
Sample Input
3 20 2 30 6 10 7 2 60 1 30 5 4 15 1 25 2 30 3 10 5 -1
Sample Output
170 miles 180 miles 90 miles
Source
陣列版和無陣列版
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int t,sum,i;
while(cin>>t&&t!=-1)
{
sum=0;
int a[t],b[t];
for(i=0; i<t; ++i)
cin>>a[i]>>b[i];
sum+=a[0]*b[0];
for(i=1; i<t; ++i)
sum+=(a[i]*(b[i]-b[i-1]));
cout<<sum<<" miles"<<endl;
}
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int x,y,z,t,sum,i;
while(cin>>t&&t!=-1)
{
sum=z=0;
for(i=0; i<t; ++i)
{
cin>>x>>y;
sum+=x*(y-z);
z=y;
}
cout<<sum<<" miles"<<endl;
}
return 0;
}
相關文章
- 軟銀在商業街測試自動駕駛巴士,以5公里時速往返行駛自動駕駛
- 理想汽車:2024年國慶期間理想汽車累計行駛里程達到5.5億公里
- 蔚來:資料顯示當前智慧駕駛總使用者數已超過30萬 使用者行駛總里程已達8.49億公里
- 美國加州機動車管理局:2021年自動駕駛測試車在加州行駛640萬公里自動駕駛
- 行駛證駕照識別開發
- three.js 汽車行駛動畫效果JS動畫
- 小米汽車:2024年十一假期小米汽車車主全國打卡367個城市 累計行駛總里程4101.12萬公里
- 行駛證OCR識別Api介面介紹API
- Speed Up Your WordPress Site
- mysql connect speed is slowMySql
- 駛向2030:汽車行業競速賽(附下載)行業
- 網路晶片應用:GPS公交車行駛記錄儀晶片
- 駛向數字智慧的瀚海,“懂行人”助力石油人乘風破浪
- 判斷環境使用 Laravel Page SpeedLaravel
- Middle Speed Decanter Centrifuge exported to KazakhstanExport
- Improving the speed of the Miller-Rabin Prime Test
- APP移動端識別行駛證、駕駛證識別技術APP
- Laravel 公眾號網頁呼叫騰訊雲行駛證識別功能Laravel網頁
- 什麼是 Dynatrace 的 Speed Index 度量標準Index
- 使用 Laravel Page Speed 優化你的專案Laravel優化
- 頁面前端效能除錯工具yslow,Page Speed前端除錯
- 2023年全球客運公里數收入同比(附原資料表)
- What's the maximum typical speed possible with a USB2.0 drive?
- Smart Witness:66.2%的英國司機質疑或反對自動駕駛汽車上路行駛自動駕駛
- 儲存產學研:如何走好“第一公里”和打通“最後一公里”
- OGEM Shale Shaker and Variable Speed Decanter Centrifuge for PDVSA ProjectProject
- 微信小程式變現駛入快車道微信小程式
- 網際網路券商駛入快車道
- 人工智慧+醫療駛入快車道人工智慧
- 世界首創新能源空鐵在我國試執行 時速60公里
- HiSpider(Hitask) is a fast and high performance spider with high speedIDEASTORM
- 把Waymo玩成GTA遊戲!全生成式的車輛行駛軌跡影片合成器來了遊戲
- JavaScript 奇數行或者偶數行JavaScript
- Flutter 敲一個靈動的錄音按鈕動畫 - Speed CodeFlutter動畫
- 企業級OLAP資料庫,怎麼打通數字化轉型最後一公里資料庫
- 產業安全專家談 | 航空產業駛入數字化快車道,如何升級智慧航空新體驗?產業
- 【基礎dp路徑記錄】HDU 1160 FatMouse's Speed
- 卓普旗艦手機Speed 8將亮相 十核處理器