首页 > 其他分享 >AtCoder Beginner Contest 153

AtCoder Beginner Contest 153

时间:2023-04-02 11:12:43浏览次数:49  
标签:AtCoder 153 Beginner Contest int ll long second

AtCoder Beginner Contest 153

https://atcoder.jp/contests/abc153
这套比较简单。

E - Crested Ibis vs Monster

完全背包

#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N = 1e3 + 5, M = 1e4 + 5;
ll n, m, a[N], b[N], f[M * 2], mx;

int main () {
    cin >> m >> n;
    for (int i = 1; i <= n; i++)    cin >> a[i] >> b[i], mx = max (mx, a[i]);
    memset (f, 0x3f, sizeof f);
    f[0] = 0;
    for (int i = 1; i <= n; i++) {

    }
    
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            f[j+a[i]] = min (f[j+a[i]], f[j] + b[i]);
        }
    }

    ll ans = 1e9;
    for (int i = m; i <= m + mx; i++)   ans = min (ans, f[i]);
    cout << ans;
}

//完全背包

F - Silver Fox vs Monster

贪心。
覆盖范围转化为 \([x_i,x_i+2d]\)。
然后二分最大覆盖范围,差分更新区间贡献

#include <bits/stdc++.h>
#define ll long long

using namespace std;
typedef pair<ll, ll> pii;
const int N = 2e5 + 5;
ll n, d, a, cnt, b[N]; //差分数组
pii p[N];

int main () {
    cin >> n >> d >> a;
    for (int i = 1; i <= n; i++) {
        cin >> p[i].first >> p[i].second;
        p[i].second = (p[i].second + a - 1) / a;
        // cout << p[i].second << ' ';
    }
    sort (p + 1, p + n + 1);

    for (int i = 1; i <= n; i++) {
        //找到第一个能被消去的
        b[i] += b[i-1];
        ll cur = p[i].second - b[i];
        if (cur <= 0)   continue;
        cnt += cur, b[i] += cur;
        ll l = i, r = n;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (p[mid].first <= p[i].first + 2 * d)     l = mid;
            else    r = mid - 1;
        }
        b[l+1] -= cur;
        // cout << i << ' ' << l << endl;
        //[i,l]都-p[i].second

    }
    cout << cnt << endl;
}

//贪心把炸弹放在xi, 则覆盖[xi,xi+2d]
//差分维护改变值, 二分最大范围
//优化: 差分 + 二分

标签:AtCoder,153,Beginner,Contest,int,ll,long,second
From: https://www.cnblogs.com/CTing/p/17280075.html

相关文章

  • AtCoder Beginner Contest 296
    DM<=ab枚举。复杂度\(O(\sqrt{m})\)。C++Code#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;intmain(){ios::sync_with_stdio(false);cin.tie(nullptr);i64n,m;cin>>n>>m;if(m&......
  • AtCoder Beginner Contest 296 ABCD
    https://atcoder.jp/contests/abc296A-Alternately#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpair<LL,LL>PII;constLLMAXN=1e18,MINN=-MAXN,INF=0x3f3f3f3f;constLLN=2e6+10,M=3023;constLLmod=100000007;cons......
  • AtCoder Beginner Contest 152
    AtCoderBeginnerContest152https://atcoder.jp/contests/abc152F我看了半天,编码方式那里还算是感觉比较玄乎,这题确实妙。D-Handstand2只需记录两端数字即可,不要想太复杂。#include<bits/stdc++.h>#definelllonglongusingnamespacestd;lln,sum,a[10][10];......
  • AtCoder Beginner Contest 295
    题解报告基本的一些理解和问题都在注释中A:ProbablyEnglish//水题#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<unordered_map>usingnamespacestd;constintmaxn=1e3+10;strings[......
  • AtCoder Beginner Contest 246
    AtCoderBeginnerContest246A(思维)A这个题大意是告诉你一个矩形的三个点,求第四个点,并且已知每条边都是平行于\(x\)轴或者是\(y\)轴的,那么我们可以确定,\(x\)坐标只有两......
  • AtCoder Beginner Contest 295
    A-ProbablyEnglish#include<bits/stdc++.h>usingnamespacestd;intread(){intx=0,f=1,ch=getchar();while((ch<'0'||ch>'9')&&ch......
  • Coinc1dens's lessons for cryptography beginner
    Coinc1dens'slessonsforcryptographybeginner10分题懒得写,赛后浅写一下(有些还真写不出来)太屑了古典懒得写,相信都写的出来1.childexgcdi即为m在模p情况下的乘法逆......
  • AtCoder Beginner Contest 145
    AtCoderBeginnerContest145https://atcoder.jp/contests/abc145D-Knight乍一看以为是dp,但是数据范围不允许。仔细一看发现,两种操作的次数是固定的,可以枚举出来每......
  • AtCoder Beginner Contest 148
    AtCoderBeginnerContest148https://atcoder.jp/contests/abc148这场比较简单D-BrickBreak二分orLIS#include<bits/stdc++.h>#definelllonglongusingn......
  • 【题解】Atcoder ABC295 A-G
    A.ProbablyEnglish题目分析:直接每一个单词判一下就好了。代码:点击查看代码#include<bits/stdc++.h>usingnamespacestd;intmain(){ intn;scanf("%d",&n); bo......