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

AtCoder Beginner Contest 294

时间:2023-07-14 17:44:26浏览次数:30  
标签:AtCoder cout Beginner int nullptr cin long tie 294

A - Filter

#include <bits/stdc++.h>

using namespace std;

#define int long long


int32_t main() {
    ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);
    int n;
    cin >> n;
    for( int x ; n ; n -- ){
        cin >> x;
        if( x & 1 ) continue;
        cout << x << " ";
    }
    return 0;
}

B - ASCII Art

#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    ios::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);
    int n , m;
    cin >> n >> m;
    for( int i = 1 , x ; i <= n ; i ++ ){
        for( int j = 1 ; j <= m ; j ++ ){
            cin >> x;
            if( x == 0 ) cout << ".";
            else cout << (char)('A'+x-1);
        }
        cout << "\n";
    }
    return 0;
}

C - Merge Sequences

模拟一下归并排序的过程

#include <bits/stdc++.h>

using namespace std;

#define int long long


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m), c, d;
    for (auto &i: a)
        cin >> i;
    for (auto &i: b)
        cin >> i;
    for (int t = 1, i = 0, j = 0; t <= n + m; t++) {
        if (i == n) d.push_back(t), j++;
        else if (j == m) c.push_back(t), i++;
        else if (a[i] <= b[j]) c.push_back(t), i++;
        else d.push_back(t), j++;
    }
    for (auto i: c)
        cout << i << " ";
    cout << "\n";
    for (auto i: d)
        cout << i << " ";
    cout << "\n";

    return 0;
}

D - Bank

用两个set模拟一下这个过程就好了。

#include <bits/stdc++.h>

using namespace std;

#define int long long

int cnt[26];

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    set<int> a, b;
    for (int i = 1; i <= n; i++)
        a.insert(i);
    for (int op, x; q; q--) {
        cin >> op;
        if (op == 1)
            b.insert(*a.begin()), a.erase(*a.begin());
        else if( op == 2 ){
            cin >> x;
            b.erase(x);
        }else
            cout << *b.begin() << "\n";
    }
    return 0;
}

E - 2xN Grid

这个双指针就可以做

#include <bits/stdc++.h>

using namespace std;

#define int long long


int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n, na, nb, res = 0;
    cin >> n >> na >> nb;
    vector<pair<int, int>> a(na);
    for (auto &[x, y]: a)
        cin >> x >> y;
    for( int i = 1 , pa = 0 , v , l  ; i <= nb ; i ++ ){
        cin >> v >> l;
        while( l ){
            int len = min( l , a[pa].second );
            if( v == a[pa].first ) res += len;
            a[pa].second -= len , l -= len;
            if( a[pa].second == 0 ) pa ++;
        }
    }
    cout << res << "\n";
    return 0;
}

F - Sugar Water 2

我们的做法就是二分答案。二分第\(k\)大的浓度是\(x\),然后统计有多少种情况混合浓度大于\(x\)

浓度大于\(x\)的情况是$\frac{A_i+C_j}{A_i+B_i+C_j+D_j} > x \(,化简可以得到\)(1-x)A_i-B_ix>(x-1)C_j+D_jx$

发现不等式两边互补影响,我们算出两种糖水的参数\(p_i=(1-x)A_i-B_ix,q_i=(x-1)C_j+D_jx\)

把\(p,q\)排序后用双指针算出有多少对\((i,j)\)满足\(p_i>q_j\)即可,复杂度\(O(\log10^{12}N\log N)\)

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double

int n, m, k;
vector<double> a, b, c, d;

constexpr double eps = 1e-12;

bool check(double x) {
    int cnt = 0;
    vector<double> p, q;
    for (int i = 0; i < n; i++)
        p.push_back((1.0 - x) * a[i] - b[i] * x);
    for (int i = 0; i < m; i++)
        q.push_back((x - 1.0) * c[i] + d[i] * x);
    sort(p.begin(), p.end()), sort(q.begin(), q.end());
    for (int i = 0, j = 0; i < n; i++) {
        while (j < m && q[j] < p[i]) j++;
        cnt += j;
    }
    return cnt >= k;
}

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cin >> n >> m >> k;
    a = vector<double>(n), b = vector<double>(n);
    c = vector<double>(m), d = vector<double>(m);
    for (int i = 0; i < n; i++)
        cin >> a[i] >> b[i];
    for (int i = 0; i < m; i++)
        cin >> c[i] >> d[i];

    double l = 0, r = 1, mid, res;
    while (r - l > eps) {
        mid = (l + r) / 2.0;
        if (check(mid)) res = mid, l = mid + eps;
        else r = mid - eps;
    }
    cout << fixed << setprecision(9) << res * 100.0;
    return 0;
}

标签:AtCoder,cout,Beginner,int,nullptr,cin,long,tie,294
From: https://www.cnblogs.com/PHarr/p/17554610.html

相关文章

  • AtCoder Beginner Contest 309 - D(最短路)
    目录D-AddOneEdge法一:dijkstra法二:BFS+队列题目传送门:abc309前面的简单题就不放了D-AddOneEdge题意:给你一个无向图图,分为两个连通块,一个顶点数为n1(1~n1),一个顶点数为n2(n1+1~n1+n2),图中共有m条边。如果现在在两个连通块之间连接一条边,那么顶点1与顶点n1+n2......
  • AtCoder Beginner Contest 162
    AtCoderBeginnerContest162ABCD全暴力E数学题看不懂,感性理解F线性dp,非常基础我不会,寄E-SumofgcdofTuples(Hard)看了题解发现好多做法都是推一堆式子,我实在看不懂(卷积莫反啥啥的呜呜呜)然后看见这个感觉比较好感性理解:(来自洛谷题解)#include<bits/stdc++.h>#def......
  • Atcoder Regular Contest 114 F - Permutation Division
    显然分成\(k\)段以后,最大化形成的排列的字典序的策略是将所有段按第一个元素的大小降序排列。由于最终排列的字典序肯定\(\ge\)原排列的字典序,因此我们考虑最大化最终排列与原排列的LCP,这部分就考虑二分答案,记\(dp_i\)表示以\(p_1\)开始\(p_i\)结尾的LDS的长度,那么......
  • AtCoder Regular Contest 164 A~C
    A题都没做出来(被自已菜晕A.TernaryDecompositionA-TernaryDecomposition(atcoder.jp)题意给定一个正整数\(N\),问是否存在\(K\)个整数,使得\(N=3^{m_1}+3^{m_2}+...+3^{m_k}\)思路首先对于一个正整数\(N\),最多有\(N\)个整数使得正式成立,即\(m_i\)全为0。再对\(N\)进行三......
  • AtCoder Beginner Contest 161
    AtCoderBeginnerContest161https://atcoder.jp/contests/abc161这套不算难,但是sb我还是写不出来是为什么呢F是个妙妙题C-ReplacingIntegerWA了一次所以放上来#include<bits/stdc++.h>#definelllonglongusingnamespacestd;intmain(){lla,b;c......
  • AtCoder Grand Contest 012 D Colorful Balls
    洛谷传送门AtCoder传送门不错的题。bxEnder32k。我们发现交换有传递性,那么我们能交换就连边,答案是\(\prod\frac{(sz)!}{\prodc_i!}\),其中\(sz\)为连通块大小,\(c_i\)为这个连通块中第\(i\)种颜色出现次数。于是我们得到了一个\(O(n^2)\)的做法。发现很多遍是无用的......
  • AtCoder Regular Contest 164 E Segment-Tree Optimization
    洛谷传送门AtCoder传送门妙妙题。我们考虑如何方便地描述一棵广义线段树。不难想到使用断点描述,即对于一个结点\([l,r]\),它的左右儿子分别是\([l,mid],[mid+1,r]\),其中\(mid\in[l,r-1]\),然后把一层缩成一个\(2^{d-1}\)的序列,每一层都是上层对应结点的\(mid......
  • Atcoder ABC 309 F
    AtcoderABC309F题意n个盒子,长宽高为\(x,y,z,\)(长宽高是相对的,可以任意调换),问是否有一个盒子可以完全容纳另一个盒子,即存在一个\(A_i={x_i,y_i,z_i},A_j={x_j,y_j,z_j}\),使得\(x_i<x_j,y_i<y_j,z_i<z_j\)思路思考一个简单的问题:对于二元组\((x,y)\),我们怎么确定存在两......
  • AtCoder Beginner Contest 309 G Ban Permutation
    洛谷传送门AtCoder传送门前置知识:[ARC132C]AlmostSorted看\(\geX\)不顺眼,怎么办呢!直接容斥!钦定\(j\)个位置满足\(|P_i-i|<X\),其余任意,就转化成了[ARC132C]AlmostSorted。具体一点就是,你设\(f_{i,j,S}\)表示前\(i\)位有\(j\)个位置满足\(|P_i-i|<......
  • atcoder绿题选做
    ABC305:E  https://atcoder.jp/contests/abc305/tasks/abc305_e题意:给定一个无向图,给定k个守卫,每个守卫有h[i]的耐力值,如果是一个在图中是被保护的要满足和守卫的距离至少为h[i],让你升序打印所有被守卫的点解题思路:可以从守卫出发,看守卫在可以走的情况下最远走到哪,最后统计......