Codeforces Round #206 (Div. 2)

只会做三个题;

A:简单题,不解释:

 1 #include<cstdio>
 2 using namespace std;
 3 
 4 int k,d;
 5 
 6 int main()
 7 {
 8     scanf("%d%d",&k,&d);
 9     if(d==0)
10     {
11         if(k>1)puts("No solution");
12         else puts("0");
13     }
14     else
15     {
16         if(k>=d)
17         {
18             for(int i=0; i<d; i++)
19                 printf("1");
20             for(int i=0; i<k-d; i++)
21                 printf("0");
22         }
23         else
24         {
25             printf("%d",d);
26             for(int i=1; i<k; i++)
27                 printf("0");
28         }
29     }
30     return 0;
31 }
View Code

B题:从第一种票的往第四种票用贪心扫一遍;

 1 #include<cstdio>
 2 #define maxn 1005
 3 using namespace std;
 4 
 5 int n,m,c[4],bus[maxn],trai[maxn],buspen[maxn];
 6 int tailpen[maxn],sum1,sum2,ans;
 7 
 8 int main()
 9 {
10     for(int i=0; i<4; i++)scanf("%d",&c[i]);
11     scanf("%d%d",&n,&m);
12     for(int i=0; i<n; i++)
13     {
14         scanf("%d",&bus[i]);
15         if(bus[i]*c[0]>c[1])buspen[i]=c[1];
16         else buspen[i]=bus[i]*c[0];
17     }
18     for(int i=0; i<m; i++)
19     {
20         scanf("%d",&trai[i]);
21         if(trai[i]*c[0]>c[1])tailpen[i]=c[1];
22         else tailpen[i]=trai[i]*c[0];
23     }
24     for(int i=0;i<n;i++)sum1+=buspen[i];
25     for(int i=0;i<m;i++)sum2+=tailpen[i];
26     if(sum1<c[2])ans+=sum1;
27     else ans+=c[2];
28     if(sum2<c[2])ans+=sum2;
29     else ans+=c[2];
30     if(ans<c[3])printf("%d",ans);
31     else printf("%d",c[3]);
32 }
View Code

C:

n件物品n+1个空,枚举他们最后相遇的那个空,然后贪心就可!

代码:

 1 #include<cstdio>
 2 #include<iostream>
 3 #define maxn 100005
 4 using namespace std;
 5 
 6 int n,l,r,ql,qr,v;
 7 long long goods[maxn],s[maxn],ans;
 8 int main()
 9 {
10     scanf("%d%d%d%d%d",&n,&l,&r,&ql,&qr);
11     for(int i=1; i<=n; i++)
12     {
13         scanf("%d",&goods[i]);
14         s[i]=s[i-1]+goods[i];
15     }
16     long long minn=9999999999999999;
17     for(int i=0;i<=n;i++)
18     {
19         v=n-i;
20         ans=s[i]*l+(s[n]-s[i])*r;
21         if (i>v+1) ans+=(i-v-1)*ql;
22         if (v>i+1) ans+=(v-i-1)*qr;
23         if (ans<minn) minn=ans;
24     }
25     cout<<minn;
26 }
View Code

 

posted @ 2013-10-15 14:55  Yours1103  阅读(168)  评论(0编辑  收藏  举报