Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

确实是只检查相邻两周

Posted by wlfinal at 2014-08-10 21:09:23 on Problem 2393
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator