santisify Site

Back

Atcoder beginner contest 331Blur image

A Tomorrow#

题目大意#

一年由 M个月组成,从 1月到 M月,每个月由 D天组成,从 1天到 D天。 问:在该日历中,年 y、月 m、日 d的下一天的日期?

参考代码#

#include <bits/stdc++.h>

#define int long long
#define endl '\n'

void solve(){
    int M, D;
    std::cin >> M >> D;
    int y, m, d;
    std::cin >> y >> m >> d;
    d ++;
    if(d > D){
        d -= D;
        m ++;
        if(m > M){
            m -= M;
            y ++;
        }
    }
    std::cout << y << " " << m << " " << d << endl;;
}

signed main () {
    std::ios::sync_with_stdio (false);
    std::cin.tie (nullptr), std::cout.tie (nullptr);
    int Lazy_boy_ = 1;
//    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve ();
    return 0;
}
cpp

B Buy One Carton of Milk#

题目大意#

一包 6个蛋 S元, 一包 8个蛋 M元,一包 12个蛋 L元 问:购买任意数量的每包鸡蛋时, 求至少购买 N个鸡蛋所需的最小价格?

解题思路#

由于数据量比较小,我们可以直接三重循环暴力跑一遍.

参考代码#

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve(){
    int n, s, m, l;
    std::cin >> n >> s >> m >> l;
    int ans = INF;
    for(int i = 0 ; i <=100 ; i ++){
        for(int j = 0; j <= 100; j ++){
            for(int k = 0 ; k <= 100; k ++){
                int w = i * s + j * m + l * k;
                if(i * 6 + 8 * j + 12 * k >= n)
                    ans = std::min (ans, w);
            }
        }
    }
    std::cout << ans << endl;
}

signed main () {
    std::ios::sync_with_stdio (false);
    std::cin.tie (nullptr), std::cout.tie (nullptr);
    int Lazy_boy_ = 1;
//    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve ();
    return 0;
}
cpp

C Sum of Numbers Greater Than Me#

题目大意#

给一个大小为 N的数组 A, 问: 数组 A中所有大于 A[i]的元素之和.

解题思路#

B数组为输入的数组, 现有 s记录数组元素的总和,数组 A记录 B数组中大小为 i的 元素个数为 A[i]个,我们在遍历一次 A数组,只要 A[i] > 0就可以将 A[i]赋值为 s - A[i] * i 当然,同时 s -= i * A[i] 最后,再遍历一次数组 B,输出 A[B[i]].

参考代码#

#include <bits/stdc++.h>

#define int long long
#define endl '\n'
const int INF = 0x3f3f3f3f;

void solve(){
    int n, s = 0, ans = 0,x;
    std::cin >> n;
    std::vector<int> a(1e6 + 50, 0ll), b(n, 0ll);
    for(int i = 0 ; i < n ; i ++)
        std::cin >> b[i], a[b[i]] ++, s += b[i];

    for(int i = 1 ; i <= 1000000 ;i ++){
        if(a[i]){
            s -= a[i] * i;
            a[i] = s;
        }
    }
    for(int i = 0 ; i < n ; i ++)
        std::cout << a[b[i]] << " ";
  
}

signed main () {
    std::ios::sync_with_stdio (false);
    std::cin.tie (nullptr), std::cout.tie (nullptr);
    int Lazy_boy_ = 1;
//    std::cin >> Lazy_boy_;
    while (Lazy_boy_--)
        solve ();
    return 0;
}
cpp
Atcoder beginner contest 331
https://santisify.top/blog/old/abc331
Author santisify
Published at August 15, 2024
Comment seems to stuck. Try to refresh?✨