标签:
Yogurt factory
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8205 | Accepted: 4197 |
Description
Input
Output
Sample Input
4 5 88 200 89 400 97 300 91 500
Sample Output
126900
Hint
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 struct node 7 { 8 int c,y; 9 }a[10000+10]; 10 int main() 11 { 12 int n,s; 13 int i; 14 long long sum; 15 //freopen("in.txt","r",stdin); 16 while(scanf("%d%d",&n,&s)!=EOF) 17 { 18 for(i=0;i<n;i++) 19 scanf("%d%d",&a[i].c,&a[i].y); 20 int sto=0; 21 sum=0; 22 for(i=0;i<n-1;i++) 23 { 24 if(sto==a[i].y) 25 sto=0; 26 else 27 sum+=a[i].c*a[i].y; 28 if((a[i].c+s)<a[i+1].c) 29 { 30 sum+=(a[i].c+s)*a[i+1].y; 31 sto=a[i+1].y; 32 } 33 } 34 if(sto!=a[n-1].y) 35 sum+=a[n-1].c*a[n-1].y; 36 printf("%lld\n",sum); 37 } 38 39 }
简单DP:
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cstring> 5 using namespace std; 6 struct node 7 { 8 int c,y; 9 }a[10000+10]; 10 int main() 11 { 12 int n,s; 13 int i; 14 long long sum; 15 freopen("in.txt","r",stdin); 16 while(scanf("%d%d",&n,&s)!=EOF) 17 { 18 sum=0; 19 for(i=0;i<n;i++) 20 scanf("%d%d",&a[i].c,&a[i].y); 21 for(i=1;i<n;i++) 22 a[i].c=min(a[i].c,a[i-1].c+s); 23 for(i=0;i<n;i++) 24 sum+=a[i].c*a[i].y; 25 printf("%lld\n",sum); 26 } 27 28 }
Yogurt factory(POJ 2393 贪心 or DP)
标签:
原文地址:http://www.cnblogs.com/a1225234/p/5166416.html