首页 > 其他分享 >ABC318

ABC318

时间:2023-09-02 23:44:16浏览次数:43  
标签:ABC318 int rep cin ++ ans ll

T1:Full Moon

模拟

代码实现
n, m, p = map(int, input().split())
ans = 0
i = m 
while i <= n:
    ans += 1
    i += p
print(ans)

或者答案是 \(\lfloor\frac{n+(p-m)}{p}\rfloor\)

T2:Overlapping sheets

模拟

代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main() {
    int n;
    cin >> n;
    
    int m = 100;
    vector s(m, vector<int>(m));
    rep(_, n) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        for (int i = a; i < b; ++i) {
            for (int j = c; j < d; ++j) {
                s[i][j] = 1;
            }
        }
    }
    
    int ans = 0;
    rep(i, m)rep(j, m) if (s[i][j] == 1) ans++;
    
    cout << ans << '\n';
    
    return 0;
}

T3:Blue Spring

贪心

  • 先将 \(f\) 做升序排序
  • 预处理一下 \(f\) 的前缀和
  • 可以枚举后缀哪几个 \(d\) 天买一日游券,剩下的前缀就都是买常规票
代码实现
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    int n, d, p;
    cin >> n >> d >> p;
    
    vector<int> f(n);
    rep(i, n) cin >> f[i];
    
    sort(f.begin(), f.end());
    
    vector<ll> s(n+1);
    rep(i, n) s[i+1] = s[i]+f[i];
    
    ll ans = 1e18;
    rep(i, n+1) {
        int r = max(0, n - i*d);
        ll now = s[r] + (ll)p*i;
        ans = min(ans, now);
        if (r == 0) break;
    }
    
    cout << ans << '\n';
    
    return 0;
}

标签:ABC318,int,rep,cin,++,ans,ll
From: https://www.cnblogs.com/Melville/p/17674413.html

相关文章