hdu5477-模拟-A Sweet Journey

来源:互联网 发布:js缺少对象 编辑:程序博客网 时间:2024/06/01 09:50

https://vjudge.net/problem/HDU-5477
给定len长度的路,有n个区间,n个区间内每米要花费 x,其他地方要获得n,行走的过程中不能为负。问你最少需要带多少能量。
模拟。注意对开头的处理。

#include <bits/stdc++.h>using namespace std;vector<pair<int,int> >k;int main(){  int n,m,a1,b1,len,t;   int a,b;   //ios::sync_with_stdio(false);   cin>>t;   for(int tt=1;tt<=t;tt++){       cin>>m>>a1>>b1>>len;       k.clear();       for(int i=0;i<m;i++){           cin>>a>>b;           k.push_back(make_pair(a,b));       }       //k.push_back(make_pair(b,len));      long long  cost=0;       int temp=0;      long long all=0;       for(int i=0;i<k.size();i++){           cost+=(k[i].first-temp)*b1;           if(cost<(k[i].second-k[i].first)*a1)           {  all+=((k[i].second-k[i].first)*a1-cost);               cost=0;           }           else           {  cost-=(k[i].second-k[i].first)*a1;           }           temp=k[i].second;       }       cout<<"Case #"<<tt<<": "<<all<<endl;    }    return 0;}
原创粉丝点击