Codeforces Round#499 (Div. 2)

比赛传送门

A. Stages

直接贪心尽量取小字母就好了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<cstdio>

int n,k,num[30];
char s[55];
int main(){
scanf("%d%d%s",&n,&k,s);
for (int i=0;i<n;i++) num[s[i]-'a'+1]++;
int lst=-1,ans=0;
while (k){
int i;bool suc=0;
for (i=lst+2;i<=26;i++)
if (num[i]) {suc=1;break;}
if (!suc) break;
ans+=i;lst=i;k--;
}
if (k) return puts("-1"),0;
printf("%d",ans);
return 0;
}

B. Planning The Expedition

二分天数,看总共是否够n个人吃

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<cstdio>

const int maxn=105;
int n,m,num[maxn];
bool check(int day){
int tot=0;
for (int i=1;i<=100;i++) tot+=num[i]/day;
return tot>=n;
}
int main(){
scanf("%d%d",&n,&m);
for (int i=1,x;i<=m;i++) scanf("%d",&x),num[x]++;
int l=1,r=10000,ans=0;
while (l<=r){
int mid=l+r>>1;
if (check(mid)) ans=mid,l=mid+1;else r=mid-1;
}
printf("%d",ans);
return 0;
}

C. Fly

显然油带得多不会影响飞行,所以二分油量即可

此题卡精度差评……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<cstdio>

const int maxn=1005;
const long double eps=1e-9;
int n,m,a[maxn],b[maxn];
bool check(long double fuel){
for (int i=2;i<=n+1;i++){
double del=(fuel+m)/a[i-1];
if (del-fuel>=eps) return 0;
fuel-=del;
del=(fuel+m)/b[i];
if (del-fuel>=eps) return 0;
fuel-=del;
}
return 1;
}
int main(){
scanf("%d%d",&n,&m);
long double ans=-1,l=0,r=1e9;
for (int i=1;i<=n;i++) scanf("%d",&a[i]),l+=(double)m/a[i];
for (int i=1;i<=n;i++) scanf("%d",&b[i]),l+=(double)m/b[i];
a[n+1]=a[1],b[n+1]=b[1];
while (r-l>=eps){
long double mid=(l+r)/2;
if (check(mid)) ans=mid,r=mid;else l=mid;
}
if (ans<0) return puts("-1"),0;
printf("%.10lf",(double)ans);
return 0;
}

D. Rocket

看这里

E. Border

看这里

F. Mars rover

看这里