2020百度之星程序设计初赛(一)

Drink

有 n 种不同的饮料,每种饮料有无限多瓶,第 i 种饮料一瓶提供 x[i] 毫升的水分,包含 y[i] 卡路里。
现在我们需要选择一种饮料一直喝,直到补充了至少 m 毫升的水分,我们想使得摄入的卡路里总和最小。请求出这个最小值。
一旦打开一瓶饮料,就一定要喝完。(1≤test≤100,1≤n≤100,1≤m≤10000)

思路:第一眼完全背包,第二眼不过整除取模练习题罢辽

//背包核心代码
for (int i=0; i<n; i++)
for (int j=a[i].x; j<M; j++) {
    f[j]=min(f[j], f[j-a[i].x]+a[i].y);
}
for (int i=m; i<M; i++) if (f[i]!=inf) {
    printf("%d\n", f[i]);
    break;
}
#include<bits/stdc++.h>
using namespace std;
const int N=105, M=1e5+5, inf=0x3f3f3f3f;
int main() {
    int t; scanf("%d", &t);
    while (t--) {
        int n,m,ans=inf; scanf("%d%d", &n,&m);
        for (int i=0; i<n; i++) {
            int x,y,c=0; scanf("%d%d", &x,&y);
            c=m/x;
            if (m%x) c++;
            ans=min(ans, c*y);
        }
        printf("%d\n",ans);
    }
    return 0;
}

GPA

小沃沃一共参加了 4 门考试,每门考试满分 100 分,最低 0 分,分数是整数。
给定四门考试的总分,请问在最优情况下,四门课绩点的和最高是多少?
分数与绩点之间的对应关系如下:...

思路:一道完全背包题

#include<bits/stdc++.h>
using namespace std;
const int N=500, M=60;
double f[N];
double get_point(int s) {
    if (s>=95 && s<=100)return 4.3;
    if (s>=90 && s<=94) return 4.0;
    if (s>=85 && s<=89) return 3.7;
    if (s>=80 && s<=84) return 3.3;
    if (s>=75 && s<=79) return 3.0;
    if (s>=70 && s<=74) return 2.7;
    if (s>=67 && s<=69) return 2.3;
    if (s>=65 && s<=66) return 2.0;
    if (s>=62 && s<=64) return 1.7;
    return 1.0; // if (s>=95 && s<=100)
}
int main() {
    std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t,a[M]; cin>>t;
    for (int i=0; i<M; i++) a[i]=60+i;
    while (t--) {
        int s; cin>>s, memset(f,0,sizeof f);
        for (int x : a)
        for (int j=x; j<=s; j++) {
            f[j]=max(f[j], f[j-x]+get_point(x));
        }
        printf("%.1lf\n", f[s]);
    }
    return 0;
}

Dec

初始有 a,ba, ba,b 两个正整数,每次可以从中选一个大于 1 的数减 1,最后两个都会减到 1,我们想知道在过程中两个数互质的次数最多是多少。
(1≤test≤1000000,1≤a,b≤1000))

思路:这种题一定要灵活,只是求两个数的最...,先预处理,然后直接取结果

#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int a,b,ans,f[N][N]; //f[i][j]表示数字i和j的最多互质次数
int main() {
    std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t; cin>>t;
    for (int i=1; i<N; i++)
    for (int j=1; j<N; j++) {
        if (__gcd(i,j)==1) f[i][j]=max(f[i-1][j], f[i][j-1])+1;
        else f[i][j]=max(f[i-1][j], f[i][j-1]);
    }
    while (t--) cin>>a>>b, cout<<f[a][b]<<'\n';
    return 0;
}

其它题还没看...

posted @ 2020-10-29 21:13  童年の波鞋  阅读(129)  评论(0编辑  收藏  举报