CF #202 div2 练习

2014-10-30 23:14:34

A:直接模拟,需要注意的只有一点:如果顾客拿着100,那么可以找3张25或者1张50加一张25

 1 /*************************************************************************
 2     > File Name: a.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Thu 30 Oct 2014 08:00:05 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <map>
14 #include <set>
15 #include <stack>
16 #include <queue>
17 #include <iostream>
18 #include <algorithm>
19 using namespace std;
20 #define lp (p << 1)
21 #define rp (p << 1|1)
22 #define getmid(l,r) (l + (r - l) / 2)
23 #define MP(a,b) make_pair(a,b)
24 typedef long long ll;
25 const int INF = 1 << 30;
26 
27 int n;
28 int a[100010];
29 int v1,v2,v3;
30 
31 int main(){
32     v1 = v2 = v3 = 0;
33     scanf("%d",&n);
34     for(int i = 1; i <= n; ++i){
35         scanf("%d",&a[i]);
36     }
37     int flag = 1;
38     for(int i = 1; i <= n; ++i){
39         if(a[i] == 25) ++v1;
40         if(a[i] == 50){
41             if(v1 == 0){
42                 flag = 0;
43                 break;
44             }
45             --v1;
46             ++v2;
47         }
48         if(a[i] == 100){
49             if(v1 && v2){
50                 --v1;
51                 --v2;
52             }
53             else if(v1 >= 3){
54                 v1 -= 3;
55             }
56             else{
57                 flag = 0;
58                 break;
59             }
60         }
61     }
62     if(flag) printf("YES\n");
63     else printf("NO\n");
64     return 0;
65 }
View Code

B:先用最小的费用算出最长的长度,然后从头开始替换,每步尽量用大的替换即可,是个贪心。

 1 /*************************************************************************
 2     > File Name: b.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com
 5     > Created Time: Thu 30 Oct 2014 08:09:39 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <map>
14 #include <set>
15 #include <stack>
16 #include <queue>
17 #include <iostream>
18 #include <algorithm>
19 using namespace std;
20 #define lp (p << 1)
21 #define rp (p << 1|1)
22 #define getmid(l,r) (l + (r - l) / 2)
23 #define MP(a,b) make_pair(a,b)
24 typedef long long ll;
25 const int INF = 1 << 30;
26 
27 int v;
28 char ans[2000000];
29 
30 struct node{
31     int a,p;
32 }t[20];
33 
34 bool cmp(node A,node B){
35     if(A.a == B.a)
36         return A.p > B.p;
37     return A.a < B.a;
38 }
39 
40 int main(){
41     scanf("%d",&v);
42     int flag = 0,top,tmin = INF,pos;
43     for(int i = 1; i <= 9; ++i){
44         scanf("%d",&t[i].a);
45         t[i].p = i;
46         if(t[i].a < tmin){
47             tmin = t[i].a;
48             pos = i;
49         }
50         if(t[i].a == tmin && t[i].p > pos)
51             pos = i;
52     }
53     if(v < tmin){
54         printf("-1\n");
55         return 0;
56     }
57     sort(t + 1,t + 10,cmp);
58     top = v / tmin;
59     int val = v - top * tmin,id = 0;
60     while(val && id < top){
61         int fee = tmin,tpos = pos;
62         for(int i = 2; i <= 9; ++i){
63             if(t[i].a - tmin > val) break;
64             if(t[i].p > tpos){
65                 tpos = t[i].p;
66                 fee = t[i].a;
67             }
68         }
69         ans[id++] = '0' + tpos;
70         val -= fee - tmin;
71     }
72     for(int i = id; i < top; ++i)
73         ans[i] = pos + '0';
74     ans[top] = '\0';
75     printf("%s\n",ans);
76     return 0;
77 }
View Code

C:考虑平均步骤:sum / (n-1),每步都会使和增加(n-1)。如果有个比较高的ai,则要特殊考虑。

  所以答案:max(maxval,[sum / (n - 1)]向上取整)。

 1 /*************************************************************************
 2     > File Name: c.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com
 5     > Created Time: Thu 30 Oct 2014 08:55:52 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <vector>
13 #include <map>
14 #include <set>
15 #include <stack>
16 #include <queue>
17 #include <iostream>
18 #include <algorithm>
19 using namespace std;
20 #define lp (p << 1)
21 #define rp (p << 1|1)
22 #define getmid(l,r) (l + (r - l) / 2)
23 #define MP(a,b) make_pair(a,b)
24 typedef long long ll;
25 const int INF = 1 << 30;
26 
27 int n;
28 ll a,tmax,sum;
29 
30 int main(){
31     scanf("%d",&n);
32     for(int i = 1; i <= n; ++i){
33         scanf("%I64d",&a);
34         sum += a;
35         tmax = a > tmax ? a : tmax;
36     }
37     printf("%I64d\n",max(tmax,(sum - 1) / (n - 1) + 1));
38     return 0;
39 }

 

posted @ 2014-10-30 23:32  Naturain  阅读(109)  评论(0编辑  收藏  举报