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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【HDU - 5477】A Sweet Journey(思维,水题)

發(fā)布時間:2023/12/10 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5477】A Sweet Journey(思维,水题) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

Master Di plans to take his girlfriend for a travel by bike. Their journey, which can be seen as a line segment of length L, is a road of swamps and flats. In the swamp, it takes A point strengths per meter for Master Di to ride; In the flats, Master Di will regain B point strengths per meter when riding. Master Di wonders:In the beginning, he needs to prepare how much minimum strengths. (Except riding all the time,Master Di has no other choice)?

Input

In the first line there is an integer t (1≤t≤501≤t≤50), indicating the number of test cases.?
For each test case:?
The first line contains four integers, n, A, B, L.?
Next n lines, each line contains two integers:?Li,RiLi,Ri, which represents the interval?[Li,Ri][Li,Ri]?is swamp.?
1≤n≤100,1≤L≤105,1≤A≤10,1≤B≤10,1≤Li<Ri≤L1≤n≤100,1≤L≤105,1≤A≤10,1≤B≤10,1≤Li<Ri≤L.?
Make sure intervals are not overlapped which means?Ri<Li+1Ri<Li+1?for each i (1≤i<n1≤i<n).?
Others are all flats except the swamps.?

Output

For each text case:?
Please output “Case #k: answer”(without quotes) one line, where k means the case number counting from 1, and the answer is his minimum strengths in the beginning.?

Sample Input

1 2 2 2 5 1 2 3 4

Sample Output

Case #1: 0

題目大意:

Mr.D 帶著他的女朋友出去旅行,資金缺乏,就騎著自行車出發(fā)了!路途中會遇到沼澤地和平坦路。每在沼澤地騎行一米,Mr.D能量值減少a,每在平坦大路上騎行一米就恢復(fù)能量值b。為了能成功到達目的地,在出發(fā)前至少需補充多少能量。

解題報告:

跟之前做過的一個機器人的差不多,數(shù)形結(jié)合一下,橫軸是到原點的距離,縱軸是能量變化,先假設(shè)原點的能量是0,最后輸出圖像的最低點就可以了。

AC代碼:

#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<vector> #include<cctype> using namespace std; typedef long long ll; const int maxn=1e4+5; int n,L,a,b; int l[maxn],r[maxn]; int main() {int t,i,j,k,cnt=0,nf;ll sum,ans;cin>>t;r[0]=0;for(;t;t--){scanf("%d%d%d%d",&n,&a,&b,&L); sum=ans=nf=0;if(nf) continue;for(i=1;i<=n;i++){scanf("%d%d",l+i,r+i);sum+=1LL*(l[i]-r[i-1])*b;sum-=1LL*(r[i]-l[i])*a;if(sum<0) {ans+=-sum;sum=0;}}printf("Case #%d: %lld\n",++cnt,ans);}return 0; }

?

總結(jié)

以上是生活随笔為你收集整理的【HDU - 5477】A Sweet Journey(思维,水题)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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