Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
确实是只检查相邻两周In Reply To:水过,只检查相邻两周不对吧,开帖希望有大神给个正确的高效解法 Posted by:cxljim2010 at 2014-05-28 11:01:02 确实是只检查相邻两周,但是要将当前周价格更新成min(这一周价格,上一周价格+S),画个折线图就能很容易明白。 #include<iostream> #include<stdio.h> #include<vector> using namespace std; struct item{ int price,cnt; }; vector<item> vec; int main(){ int s,n; int a,b; scanf("%d%d",&n,&s); while(n--){ item t; scanf("%d%d",&t.price,&t.cnt); vec.push_back(t); } for(int i=1;i<vec.size();i++) vec[i].price = min(vec[i].price,vec[i-1].price+s); long long res = 0; for(int i=0;i<vec.size();i++) res+=(vec[i].price*vec[i].cnt); printf("%lld\n",res); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator