主頁 >  其他 > AtCoder Beginner Contest 308

AtCoder Beginner Contest 308

2023-07-02 07:53:58 其他

這幾天在收拾東西搬家,先附上代碼,晚點補上題解
感覺這次FG都寫不太明白

A - New Scheme (abc308 A)

題目大意

給定八個數,問是否滿足以下要求:

  • 不嚴格升序
  • 每個數在\(100 \sim 675\)之間
  • 每個數都是 \(25\)的倍數

解題思路

依次對每個數判斷是否符合這三個條件即可,

神奇的代碼
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(void) {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    array<int, 8> a;
    for(auto &i : a)
        cin >> i;
    auto ok = [&](){
        for(int i = 0; i < 8; ++ i){
            if (i && a[i] < a[i - 1])
                return false;
            if (a[i] < 100 || a[i] > 675)
                return false;
            if (a[i] % 25)
                return false;
        }
        return true;
    };
    if (ok())
        cout << "Yes" << '\n';
    else 
        cout << "No" << '\n';

    return 0;
}



B - Default Price (abc308 B)

題目大意

<++>

解題思路

<++>

神奇的代碼
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(void) {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    map<string, int> price;
    vector<string> a(n);
    for(auto &i : a)
        cin >> i;
    vector<string> col(m);
    for(auto &i : col)
        cin >> i;
    int ano;
    cin >> ano;
    for(auto &i : col){
        int p;
        cin >> p;
        price[i] = p;
    }
    int ans = 0;
    for(auto &i : a){
        if (price.find(i) == price.end())
            ans += ano;
        else 
            ans += price[i];
    }
    cout << ans << '\n';

    return 0;
}



C - Standings (abc308 C)

題目大意

<++>

解題思路

<++>

神奇的代碼
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(void) {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<array<int, 2>> p(n);
    for(auto &i : p)
        cin >> i[0] >> i[1];
    vector<int> id(n);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int a, int b){
        LL l = 1ll * p[a][0] * (p[b][0] + p[b][1]);
        LL r = 1ll * p[b][0] * (p[a][0] + p[a][1]);
        return l != r ? l > r : a < b;
    });
    for(auto &i : id)
        cout << i + 1 << ' ';
    cout << '\n';

    return 0;
}



D - Snuke Maze (abc308 D)

題目大意

<++>

解題思路

<++>

神奇的代碼
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

array<int, 4> dx{1, -1, 0, 0};
array<int, 4> dy{0, 0, 1, -1};

int main(void) {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    int h, w;
    cin >> h >> w;
    vector<string> tu(h);
    for(auto &i : tu)
        cin >> i;
    string target = "snuke";
    vector<vector<vector<int>>> visit(h, vector<vector<int>>(w, vector<int>(target.size(), 0)));
    function<bool(int, int, int)> dfs = [&](int x, int y, int len){
        visit[x][y][len] = 1;
        if (tu[x][y] != target[len])
            return false;
        if (x == h - 1 && y == w - 1)
            return true;
        for(int i = 0; i < 4; ++ i){
            int nx = x + dx[i], ny = y + dy[i], nlen = (len + 1) % target.size();
            if (nx < 0 || nx >= h || ny < 0 || ny >= w || visit[nx][ny][nlen])
                continue;
            if (dfs(nx, ny, nlen))
                return true;
        }
        return false;
    };
    auto ok = [&](){
        return dfs(0, 0, 0);
    };
    if (ok())
        cout << "Yes" << '\n';
    else 
        cout << "No" << '\n';

    return 0;
}



E - MEX (abc308 E)

題目大意

<++>

解題思路

如果是找兩個字符,比如EX,我們可以從右往左統計每個X對應的陣列\(a\)的值,這樣對于此時的每一個 E,假設對應的陣列\(a\)的值是 \(e\),那么所有 EX的組成的mex只有三種情況:

  • \(mex(e, 0)\)
  • \(mex(e, 1)\)
  • \(mex(e, 2)\)

此時以該E開始,右邊的所有X組成的EX,對答案的貢獻就分這三類,因此我們就記錄一下右邊有多少個是\(0\)X\(1\)X\(2\)X,然后乘以對應的mex值就是對答案的貢獻,

解決了EX,對于MEX,其實可以看成MEX,只是這時候的EX\(6\)種情況:

  • mex(M, 0, 0)
  • mex(M, 0, 1)
  • mex(M, 0, 2)
  • mex(M, 1, 1)
  • mex(M, 1, 2)
  • mex(M, 2, 2)

同樣我們就記錄EX分別是\(00,01,02,11,12,22\)這些情況的數量,再乘以對應的 mex值,就是該M對答案的貢獻,而統計EX 的數量就是剛剛的問題,

代碼里記錄\(00,01\)的情況用的二進制狀壓的方法,

神奇的代碼
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(void) {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &i : a)
        cin >> i;
    string s;
    cin >> s;
    array<int, 3> x{};
    array<LL, 8> ex{};
    map<int, int> tr{{0, 1}, {1, 2}, {2, 4}};
    map<int, int> mex;
    auto get_mex = [&](int x, int y, int z){
        set<int> candidate{0, 1, 2, 3};
        if (candidate.count(x))
            candidate.erase(x);
        if (candidate.count(y))
            candidate.erase(y);
        if (candidate.count(z))
            candidate.erase(z);
        return *candidate.begin();
    };
    for(int i = 0; i < 3; ++ i)
        for(int j = 0; j < 3; ++ j)
            for(int k = 0; k < 3; ++ k){
                mex[tr[i] | tr[j] | tr[k]] = get_mex(i, j, k);
            }
    LL ans = 0;
    for(int i = n - 1; i >= 0; -- i){
        if (s[i] == 'X'){
            x[a[i]] ++;
        }else if (s[i] == 'E'){
            for(int j = 0; j < 3; ++ j){
                int status = (tr[a[i]] | tr[j]);
                ex[status] += x[j];
            }
        }else{
            for(int j = 0; j < 8; ++ j){
                ans += mex[tr[a[i]] | j] * ex[j];
            }
        }
    }
    cout << ans << '\n';

    return 0;
}



F - Vouchers (abc308 F)

題目大意

<++>

解題思路

兩種方向,分別按照商品價格的升序或降序依次考慮,

可以發現以升序方式考慮的話,先前考慮的優惠券同樣適用后面的商品,因此我們就可以從這些未使用且可使用的優惠券中選優惠力度最大的,

考慮是否存在反例,因為每個商品只能用一個優惠券,因此每次都只會從未使用中選最好的一個,當考慮一個新商品,同時還有更多的優惠券變得可使用時,這些優惠券不能代替先前的優惠券適用(不滿足最低價格),因此也替換不了,

感覺這個貪心貌似就對了,

神奇的代碼
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(void) {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    for(auto &i : p)
        cin >> i;
    vector<array<int, 2>> coupon(m);
    for(auto &i : coupon)
        cin >> i[1];
    for(auto &i : coupon)
        cin >> i[0];
    priority_queue<array<int, 2>> best{};
    sort(p.begin(), p.end());
    sort(coupon.begin(), coupon.end(), [](const auto& a, const auto& b){
            return a[1] < b[1];
            });
    int pos = 0;
    LL ans = 0;
    for(auto &i : p){
        while(pos < m && coupon[pos][1] <= i){
            best.push(coupon[pos]);
            ++ pos;
        }
        int discout = 0;
        if (!best.empty()){
            discout = best.top()[0];
            best.pop();
        }
        ans += i - discout;
    }
    cout << ans << '\n';

    return 0;
}



G - Minimum Xor Pair Query (abc308 G)

題目大意

<++>

解題思路

不考慮修改,從陣列里選兩個異或值最小,我們可以遍歷由這n個數構成的trie數,我們選擇的兩個數盡量選擇同一邊的,如果某個節點下只有兩個數,且是該節點產生分歧的,此時就選擇這兩個數的異或者,作為一個備選答案,通過一次dfs就能得到,

考慮修改的話,我們發現上述產生答案的資訊是可以實時維護的,于是問題貌似就解決了?

具體來說,考慮一個節點\(u\),左兒子(二進制下為\(0\))\(lson\),右兒子(二進制下為\(1\))\(rson\)

  • 如果\(u\)下只有兩個數,一個數在 \(lson\)子樹內,一個在 \(rson\)內,那以 \(u\)節點的子樹的最小異或值 \(ans_u = lson \oplus rson\),一般我們要遍歷到葉子才知道這個\(lson,rson\)是多少,但為了減少時間復雜度,可以把這個資訊往上提到\(lson,rson\)處,這樣就不用遍歷到葉子,
  • 如果\(lson\)下有至少兩個數,那么以\(u\)節點的子樹的最小異或值 \(ans_u = min(ans_u, ans_{lson})\),而\(ans_{lson}\)是個子問題,
  • 如果\(rson\)下有至少兩個數,那么以\(u\)節點的子樹的最小異或值 \(ans_u = min(ans_u, ans_{rson})\)\(ans_{rson}\)同樣是個子問題,

對于葉子節點,如果該葉子對應兩個數,那么 \(ans_{leaf} = 0\),否則為無窮大,

對于題意的增加和洗掉,這些資訊都可以在進行這些操作時\(O(1)\)維護,感覺就可以了,

神奇的代碼
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const int inf = (1 << 30) + 114514;
const int SZ = 2;
template<typename T, typename K>
struct Trie {
    struct node {
        K value;
        int ans;
        int vis_count;
        array<int, SZ> children;

        node(K val) : value(val) {
            vis_count = 0;
            fill(children.begin(), children.end(), 0);
            ans = inf;
        }
    };

    int cast(K val) {
        int ret = val;  
        assert(ret < SZ and ret >= 0);
        return ret;
    }

    vector<node> tree;

    Trie(K val) {
        tree.push_back(node(val));
    }

    void insert(int v, int pos, int cur, const T &sequence, bool remove = false) {

        if (remove) {
            tree[cur].vis_count -= 1;
        } else {
            tree[cur].vis_count += 1;
        }

        if (pos < sequence.size()){

            K value = https://www.cnblogs.com/Lanly/archive/2023/07/02/sequence[pos];
            if (tree[cur].children[cast(value)] == 0) {
                tree[cur].children[cast(value)] = (int) tree.size();
                tree.emplace_back(v);
            }

            insert(v, pos + 1, tree[cur].children[cast(value)], sequence, remove);

            if (tree[cur].vis_count == 1){
                int lson = tree[cur].children[cast(value)];
                int rson = tree[cur].children[cast(value) ^ 1];
                if (lson != 0 && tree[lson].vis_count != 0)
                    tree[cur].value = tree[lson].value;
                else 
                    tree[cur].value = tree[rson].value;
            }

            tree[cur].ans = inf;
            int lson = tree[cur].children[0], rson = tree[cur].children[1];
            if (lson != 0 && tree[lson].vis_count > 1)
                tree[cur].ans = min(tree[cur].ans, tree[lson].ans);
            if (rson != 0 && tree[rson].vis_count > 1)
                tree[cur].ans = min(tree[cur].ans, tree[rson].ans);
            if (lson != 0 && rson != 0 && tree[lson].vis_count == 1 && tree[rson].vis_count == 1)
                tree[cur].ans = tree[lson].value ^ tree[rson].value;
        }else{
            tree[cur].ans = inf;
            if (tree[cur].vis_count > 1)
                tree[cur].ans = 0;
        }
    }

    void remove(int v, const T& sequence) {
        insert(v, 0, 0, sequence, true);
    }

    int get_min(){
        return tree.front().ans;
    }

};

int main(void) {
    ios::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    Trie, int> tree(0);
    auto tr2bin = [](int x){
        array bin{};
        for(int i = 0; i < 30; ++ i){
            bin[i] = ((x >> (29 - i)) & 1);
        }
        return bin;
    };

    int q;
    cin >> q;
    while(q--){
        int op;
        cin >> op;
        if (op == 1){
            int x;
            cin >> x;
            tree.insert(x, 0, 0, tr2bin(x));
        }else if (op == 2){
            int x;
            cin >> x;
            tree.remove(x, tr2bin(x));
        }else{
            cout << tree.get_min() <<'\n';
        }
    }

    return 0;
}



Ex - Make Q (abc308 Ex)

題目大意

<++>

解題思路

<++>

神奇的代碼



轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/556478.html

標籤:其他

上一篇:C++ 核心指南之資源管理(下)—— 智能指標最佳實踐

下一篇:返回列表

標籤雲
其他(161980) Python(38266) JavaScript(25519) Java(18286) C(15238) 區塊鏈(8275) C#(7972) AI(7469) 爪哇(7425) MySQL(7280) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5876) 数组(5741) R(5409) Linux(5347) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4609) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2438) ASP.NET(2404) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) .NET技术(1985) HtmlCss(1982) 功能(1967) Web開發(1951) C++(1942) python-3.x(1918) 弹簧靴(1913) xml(1889) PostgreSQL(1882) .NETCore(1863) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • AtCoder Beginner Contest 308

    > 這幾天在收拾東西搬家,先附上代碼,晚點補上題解 > 感覺這次FG都寫不太明白 ## [A - New Scheme (abc308 A)](https://atcoder.jp/contests/abc308/tasks/abc308_a) ### 題目大意 給定八個數,問是否滿足以下要求: - ......

    uj5u.com 2023-07-02 07:53:58 more
  • C++ 核心指南之資源管理(下)—— 智能指標最佳實踐

    > C++ 核心指南(C++ Core Guidelines)是由 Bjarne Stroustrup、Herb Sutter 等頂尖 C+ 專家創建的一份 C++ 指南、規則及最佳實踐。旨在幫助大家正確、高效地使用“現代 C++”。 > > 這份指南側重于介面、資源管理、記憶體管理、并發等 High ......

    uj5u.com 2023-07-02 07:53:53 more
  • 牛客小白月賽75

    # A.上班 ### 題意: ![](https://img2023.cnblogs.com/blog/2960080/202307/2960080-20230701100716620-968916608.png) ![](https://img2023.cnblogs.com/blog/29600 ......

    uj5u.com 2023-07-02 07:48:30 more
  • HO引擎近況20230701

    6月份忘了來寫博客了,原因主要就是我離職了,好多事所以這個徹底忘了 離職的原因是公司說現金流斷了,沒錢了,整個專案組都砍了,別的專案組據說也快了 于是這個月就在找作業中,各種原因,真的不好找 我感覺可以自己需要再去充充電了,而且需要開拓一下自己以前想做沒做的方面,為以后多留幾條路 UE5 也升級到5 ......

    uj5u.com 2023-07-02 07:43:19 more
  • 如何快速截圖、拉紅框、紅箭頭

    ? 一、如何快速截圖 方法1(windows自帶截圖工具): 第一步:同時按住鍵盤上的“Shift”、"?win”和“S”【即Shift+win+S】,則會出現下圖中的畫面: 第二步:這個時候框選住你需要的畫面之后,會在右下角彈出以下彈窗: 第三步:點擊這個彈窗,則會出現“截圖和草圖”視窗: 第四步 ......

    uj5u.com 2023-07-02 07:43:06 more
  • 變分自編碼器(VAE)公式推導

    論文原文:Auto-Encoding Variational Bayes [[OpenReview (ICLR 2014)](https://openreview.net/forum?id=33X9fd2-9FyZd) | [arXiv](https://arxiv.org/abs/1312.611 ......

    uj5u.com 2023-07-02 07:42:56 more
  • Ubuntu虛擬機教程

    ### 1.下載ubuntu鏡像 可以去中科大鏡像站下載(本次下載20.04版本,不同版本操作會有差異,建議保持一致) ```html https://mirrors.ustc.edu.cn/ ``` 點擊如圖所示的按鈕下載![image.png](https://cdn.nlark.com/yuq ......

    uj5u.com 2023-07-02 07:42:51 more
  • 解密Prompt系列10. 思維鏈COT原理探究

    這一章我們追本溯源,討論下COT的哪些元素是提升模型表現的核心。結合兩篇論文的實驗結論,可能導致思維鏈比常規推理擁有更高準確率的因素有:思維鏈的推理程序會重復問題中的核心物體;正確邏輯推理順序的引入 ......

    uj5u.com 2023-07-02 07:42:28 more
  • 變分自編碼器(VAE)公式推導

    論文原文:Auto-Encoding Variational Bayes [[OpenReview (ICLR 2014)](https://openreview.net/forum?id=33X9fd2-9FyZd) | [arXiv](https://arxiv.org/abs/1312.611 ......

    uj5u.com 2023-07-02 07:41:18 more
  • 解密Prompt系列10. 思維鏈COT原理探究

    這一章我們追本溯源,討論下COT的哪些元素是提升模型表現的核心。結合兩篇論文的實驗結論,可能導致思維鏈比常規推理擁有更高準確率的因素有:思維鏈的推理程序會重復問題中的核心物體;正確邏輯推理順序的引入 ......

    uj5u.com 2023-07-02 07:40:55 more