4月6日

poj2393

题意:牛奶生产奶酪为第i周ci元/单位,存储为每周s元/单位,每周卖掉yi单位,求成本花费的最小值

分析:这个问题就是比较这一周自己生产和前面某一周生产以后存储到本周二者的最小值

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 const int maxn=10100;
15 int y[maxn],c[maxn];
16 int n,s;
17 int main()
18 {
19     while(cin>>n>>s)
20     {
21         for(int i=0;i<n;i++)
22             scanf("%d%d",&y[i],&c[i]);
23         for(int i=1;i<n;i++)
24             y[i]=min(y[i-1]+s,y[i]);
25         long long sum=0;
26         for(int i=0;i<n;i++)
27             sum+=y[i]*c[i];
28         cout<<sum<<endl;
29     }
30     return 0;
31 }
View Code

 poj1017

题意:有1*1,2*2,3*3,4*4,5*5,6*6,6中盒子,每种有ai个,求最少用多少6*6的盒子可以装完

分析:(1)6*6的放一个,(2)5*5的最多跟11个1*1的放一个,(3)4*4的最多可以跟2个3*3,20个1*1,(4)3*3的用4个可以,(4)3*3的可以放1个2*2,5个1*1

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <string>
 5 #include <vector>
 6 #include <algorithm>
 7 #include <set>
 8 #include <map>
 9 #include <bitset>
10 #include <cmath>
11 #include <queue>
12 #include <stack>
13 using namespace std;
14 int s1,s2,s3,s4,s5,s6;
15 int main()
16 {
17     while(cin>>s1>>s2>>s3>>s4>>s5>>s6)
18     {
19         if(s1+s2+s3+s4+s5+s6==0) break;
20         int cnt=0;
21         cnt+=s6;  //对剩余的6*6的处理
22         s6=0;
23         cnt+=s5;  //对剩余的5*5的处理
24         s1-=11*s5;
25         s5=0;
26         s1=max(0,s1);
27         cnt+=s4;   //对剩余的4*4的处理
28         if(s2>=(s4*5)){
29             s2-=s4*5;
30         }
31         else{
32             int s=6*6*s4-4*4*s4-2*2*s2;
33             s1-=s;
34             s1=max(s1,0);
35             s2=0;
36         }
37         s4=0;
38         cnt+=(s3+3)/4;  //对剩余的3*3的处理
39         s3%=4;
40         if(s3)
41         {
42             if(s2>=7-2*s3)
43             {
44                 s2-=7-2*s3;
45                 s1=max(0,s1-(8-s3));
46 
47             }
48             else{
49                 s1=max(0,s1-(36-9*s3-4*s2));
50                 s2=0;
51             }
52         }
53         s3=0;
54         cnt+=(s2+8)/9;    //对剩余的2*2进行处理
55         s2%=9;
56         if(s2)
57         s1=max(0,s1-(36-4*s2));
58         s2=0;
59         cnt+=(s1+35)/36;  //对剩余的1*1进行处理
60         cout<<cnt<<endl;
61     }
62     return 0;
63 }
View Code
原文地址:https://www.cnblogs.com/wolf940509/p/5361241.html