zoukankan      html  css  js  c++  java
  • 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
    ", ans);
    }
    
  • 相关阅读:
    数据库自动备份
    VC查找文件特定位置的记录方法
    MFC利用ADO连接ACCESS数据库及其操作数据库的方法
    VC利用ODBC连接MySql数据库的方法及其操作数据的方法
    uwsgi和nginx的故事
    A JavaScript Image Gallery
    The DOM in JavaScript
    A brief look at the Objects in JavaScript
    3 ways of including JavaScript in HTML
    #3 working with data stored in files && securing your application (PART II)
  • 原文地址:https://www.cnblogs.com/dyhaohaoxuexi/p/14375596.html
Copyright © 2011-2022 走看看