Loading

AtCoder Beginner Contest 095

A - Something on It

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int sum = 700;
int main() {
    string s;
    cin >> s;
    for (int i = 0; i < 3; i++)
        if (s[i] == 'o') sum += 100;
    cout << sum << endl;
    return 0;
}

B - Bitter Alchemy

给出两个数n和x,以及n种馅饼做一个所需的面粉重量

代表有x克面粉,需要做n种馅饼,每种都至少要做一个,最多能做多少个馅饼

先每种做一个,然后只做所需面粉最少的即可

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int n, sum, a[N], res;
int main() {
    cin >> n >> sum;
    for (int i = 0; i < n; i++) cin >> a[i], sum -= a[i];
    sort(a, a + n);
    res = n + sum / a[0];
    cout << res << endl;
    return 0;
}

C - Half and Half

给出a b c x y

现在有123三种披萨,第1种是单纯的A披萨,第2种是单纯的B披萨,第3种是AB双拼披萨,他们的单价分别为abc

现在要买x个A披萨和y个B披萨,最少花费是多少

首先看是单买A和B便宜,还是买双拼便宜,在此基础上,看是单买A或者单买B便宜还是双拼便宜

#include<bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int a, b, c, x,y;
int res = 0;
int main(){
    cin >> a >> b >> c >> x >> y;
    if(2*c<a+b){
        res += min(x, y) * 2 * c;
        if(x>y){
            res += min(2 * c, a) * (x - y);
        }
        else{
            res += min(2 * c, b) * (y - x);
        }
    }
    else{
        res += a * x + b * y;
    }
    cout << res << endl;
    return 0;
}

D - Static Sushi

一个长度为C的圆环上有n个食品,他们距离起点的距离为xi,能量为vi,现在一个人从起点出发,每走1米需要消耗1点能量,随时可以停止进食,问停止时最大的能量是多少

四种情况,顺时针、逆时针、先顺时针吃再逆时针,先逆时针再顺时针

#include<bits/stdc++.h>

using namespace std;
#define LL long long 
const int MaxN = 1e5 + 7;
LL a[MaxN], b[MaxN];  
LL x[MaxN], v[MaxN];

int main()
{
    LL n, c;
    scanf("%lld %lld", &n, &c);
    for(int i = 1; i <= n; i++) 
        scanf("%lld %lld", &x[i], &v[i]);
    
    for(LL i = 1; i <= n; i++) 
        a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);  // 顺时针走到i点时的能量
    x[n + 1] = c;
    for(LL i = n; i >= 1; i--) 
        b[i] = b[i + 1] + v[i] - (x[i+1] - x[i]);  // 逆时针走到i点时的能量

    for(LL i = 2; i <= n; i++) 
        a[i] = max(a[i-1], a[i]);  //走或者不走(和走之前的值进行比较)
    for(LL i = n-1; i >= 1; i--) 
        b[i] = max(b[i], b[i + 1]);

    LL ans = 0;
    for(LL i = 1; i <= n; i++) {
        ans = max(ans, a[i] - x[i] + b[i + 1]);  // 顺时针走后并返回一次的值
        ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);  // 逆时针走后返回一次的值
        ans = max(ans, a[i]);  // 顺时针的最大值
        ans = max(ans, b[i]); //逆时针的最大值
    }

    printf("%lld\n", ans);
}
posted @ 2021-02-04 23:43  WinterFa1L  阅读(95)  评论(0)    收藏  举报