首页 > 其他分享 >SMU Summer 2024 Contest Round 5

SMU Summer 2024 Contest Round 5

时间:2024-07-19 14:40:00浏览次数:9  
标签:Summer ve int SMU 2024 ++ xx vector yy

A Robot Takahashi

思路:

将所有数排序,枚举孩子成人的分解点X,同时根据s的标识维护正真的孩子成人的个数

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int sum = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == '1') sum ++;
    }
    vector<PII> w(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i].first;
        w[i].second = i;
    }
    sort(w.begin(), w.end());
    int a1 = sum, a0 = 0, ans = a1;
    for (int i = 0; i < w.size(); ++i) {
        int j = i;
        while (j < w.size() && w[j].first == w[i].first) {
            if (s[w[j ++].second] == '1') a1 --;
            else a0 ++;
        }
        i = j - 1;
        ans = max(ans, a1 + a0);
    }
    cout << ans;
}

B Connect 6

思路:

暴力枚举,注意对角线有两种\和/

void solve() {
    int n;
    cin >> n;
    vector<string> ve(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> ve[i];
        ve[i] = ' ' + ve[i];
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            int a = 0, b = 0, c = 0, d = 0;
            for (int k = 0; k < 6; ++k) {
                if (i >= 6 && j >= 6 && ve[i - k][j - k] == '#') a++;
                if (i >= 6 && j + 5 <= n && ve[i - k][j + k] == '#') d++;
                if (j >= 6 && ve[i][j - k] == '#') b++;
                if (i >= 6 && ve[i - k][j] == '#') c++;
            }
            if (a >= 4 || b >= 4 || c >= 4 || d >= 4) {
                cout << "Yes";
                return ;
            }
        }
    }
    cout << "No";
    return ;
}

C Strange Balls

思路:

用栈维护连续相同的数字及其个数,若满足数字等于个数就取出,同时记录总个数即为答案

void solve() {
    int n;
    cin >> n;
    vector<int> cnt (n + 1);
    vector<PII> ve;
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        if (ve.size() && ve.back().first == x) {
            ve.back().second ++, ans ++;
        } else {
            ve.push_back({x, 1}), ans ++;
        }
        if (ve.size() && ve.back().first == ve.back().second) {
            ans -= ve.back().second;
            ve.pop_back();
        }
        cout << ans << '\n';
    }
}

D Linear Probing

思路:

用类似路径压缩的方式找到下一个空的位置

数组不是很大,也可以直接用set存所有空的位置,每次赋值时二分找位置,找到后从set中删掉该位置,注意的是可能位置太靠后以至于后面没有空位置,那就手动把位置调到0即可

void solve() {
    int q;
    cin >> q;
    int n = pow(2, 20);
    vector<int> val(n, -1);
    set<int> se;
    for (int i = 0; i < n; ++i) {
        se.insert(i);
    }
    while (q --) {
        int t, x;
        cin >> t >> x;
        int s = x;
        x %= n;
        if (t == 2) {
            cout << val[x] << '\n';
        } else {
            auto p = se.lower_bound(x);
            if (p == se.end()) {
                x = 0;
                p = se.lower_bound(x);
            }
            val[*p] = s;
            se.erase(p);
        }
    }

}

F Stronger Takahashi

题目链接

思路:01bfs,优先做0步的操作,再做1步的操作,用双端队列维护

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int dxx[20] = {-2, -2, -2, -1, -1,
               -1, -1, -1, 0, 0,
               0, 0, 1, 1, 1,
               1 ,1, 2, 2, 2};
int dyy[20] = {-1, 0, 1, -2, -1,
               0, 1, 2, -2, -1,
               1, 2, -2, -1, 0,
               1, 2, -1, 0, 1};

void solve() {
    int h, w;
    cin >> h >> w;
    vector<string> ve(h + 1);
    for (int i = 1; i <= h; ++i) {
        cin >> ve[i];
        ve[i] = ' ' + ve[i];
    }
    deque<pair<PII, int> > q;
    vector<vector<int> > dis(h + 1, vector<int> (w + 1, -1));
    q.push_back({{1, 1}, 0});
    while (q.size()) {
        auto [u, ww] = q.front();
        q.pop_front();
        int x = u.first, y = u.second;
        if (dis[x][y] != -1) continue;
        dis[x][y] = ww;
        for (int i = 0; i < 4; ++i) {
            int xx = x + dx[i], yy = y + dy[i];
            if (xx < 1 || xx > h || yy < 1 || yy > w || ve[xx][yy] != '.') continue;
            q.push_front({{xx, yy}, ww});
        }
        for (int i = 0; i < 20; ++i) {
            int xx = x + dxx[i], yy = y + dyy[i];
            if (xx < 1 || xx > h || yy < 1 || yy > w) continue;
            q.push_back({{xx, yy}, ww + 1});
        }
    }
    cout << dis[h][w];
}

E Red Polyomino

题目链接

思路:暴力dfs+剪枝,枚举下一步改颜色的位置

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

void solve() {
    int n, k;
    cin >> n >> k;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) cin >> s[i];
    map<vector<string>, int> st;
    int ans = 0;
    auto dfs = [&] (int cnt, auto dfs) -> void {
        if (st.count(s)) return ;
        st[s] = 1;
        if (cnt == 0) {
            ans ++;
            return ;
        }
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (s[i][j] == '.') {
                    for (int k = 0; k < 4; ++k) {
                        int xx = i + dx[k], yy = j + dy[k];
                        if (xx < 0 || xx >= n || yy < 0 || yy >= n) continue;
                        if (s[xx][yy] == 'j') {
                            s[i][j] = 'j';
                            dfs(cnt - 1, dfs);
                            s[i][j] = '.';
                            break;
                        }
                    }
                }
            }
        }
    };
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (s[i][j] == '.') {
                s[i][j] = 'j';
                dfs(k - 1, dfs);
                s[i][j] = '.';
            }
        }
    }
    cout << ans;
}

 

G Predilection

题目链接

思路:

递推,相邻的数才进行合并,用f[i]表示前i个数的答案

第i个数没合并前,与f[i - 1]个序列构成一种序列,贡献为f[i - 1]

第i个数合并后,与f[i - 1]个序列的最后一个数进行合并,贡献为f[i - 1]

但是存在0的话会有重复的情况,就需要消去加入a[i]后出现的0带来的贡献,即找到后缀和为0的最大下标j,消去的贡献为f[j - 1]

为啥只消最大的下标j呢,因为之前的已经f[j]消掉了

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1), r(n + 5);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; --i) {
        r[i] = a[i] + r[i + 1];
    }
    map<int, int> pre;
    vector<int> f(n + 1);
    f[1] = 1;
    for (int i = 2; i <= n; ++i) {
        f[i] = f[i - 1] * 2 % mod;
        f[i] = (f[i] - pre[r[i]] + mod) % mod;
        pre[r[i]] = f[i - 1];
    }
    cout << f[n];
}

 

标签:Summer,ve,int,SMU,2024,++,xx,vector,yy
From: https://www.cnblogs.com/bible-/p/18311431

相关文章

  • 找到完美匹配:2024年最佳免费缺陷管理工具
    国内外主流的10款缺陷跟踪工具对比:PingCode、Worktile、滴答清单、CalendarTask、专注清单、Todo清单、Jira、Bugzilla、MantisBT、Redmine。在寻找合适的缺陷管理工具时,很多团队面临一个共同的挑战:如何在有限的预算内找到既高效又易于使用的解决方案。许多免费工具虽然诱人,但......
  • 【稳定检索】2024年数据处理与人工智能国际会议(ICDPAI 2024)
    2024年数据处理与人工智能国际会议2024InternationalConferenceonDataProcessingandArtificialIntelligence【1】会议简介        2024年数据处理与人工智能国际会议是数据处理和人工智能领域的一次重要盛会。会议旨在通过全球范围内专家学者的深入交流,探......
  • SURE:增强不确定性估计的组合拳,快加入到你的训练指南吧 | CVPR 2024
    论文重新审视了深度神经网络中的不确定性估计技术,并整合了一套技术以增强其可靠性。论文的研究表明,多种技术(包括模型正则化、分类器改造和优化策略)的综合应用显着提高了图像分类任务中不确定性预测的准确性来源:晓飞的算法工程笔记公众号论文:SURE:SUrveyREcipesforbuild......
  • UNR2024 游记
    Day-2高考结束之后一直在摆烂。每天大概就是,打游戏,看视频,聊天,随机胡题。果然,假期是很难有动力认真干什么事情的。又把元气骑士下回来了。这太童年了。打了几把,感觉现在元气的难度低了好多了。\(\color{orange}{\text{serenity}}\)一枪\(\color{red}{\text{120}}\),开个双......
  • 都2024年了,还在问网络安全怎么入门,气得我当场脑血栓发作
    前言本人从事网路安全工作12年,曾在2个大厂工作过,安全服务、售后服务、售前、攻防比赛、安全讲师、销售经理等职位都做过,对这个行业了解比较全面。下面就开始进入正题,如何从一个萌新一步一步进入网络安全行业。正题首先,在准备进入这个行业之前,我们要问一下我们的内心,工作千......
  • 2024牛客暑期多校训练营2 B.MST(题解)
    题意给一张\(n\)个点,\(m\)条边的无向图,\(q\)次询问,每次询问给\(k\)个结点,问这\(k\)个结点的诱导子图(也就是原图中抽出这些结点,以及原图中这些节点之间有的边)的最小生成树是多少,不连通输出-1,保证\(q\)次询问加起来问到的点的数量\(\sumk_i\leq10^5\)。思路......
  • 20240713 报错fcntl
    消费机报错:昨天晚上消费机连不上网了,今早依旧,同事重启了一下docker,就好了。抽空要学一下docker和服务器部署。消费机同步订单接口:因为昨天没连上网,我尝试刷脸消费,结果成功了。多了一条离线消费记录。也爆露出来少个离线同步订单的接口。请求的数据:{"Count":"1","D......
  • 20240718 数据库外键报错
    报错1. 1452-Cannotaddorupdateachildrow:aforeignkeyconstraintfails(bvn'.'user_user_role^,CONSTRAINT^user_user_role_user_id_e615b4e0_fk_user_user_idFOREIGNKEY(user_id’)REFERENCES^user_user(id'))翻译:不能添加或更新子行:外键约束失败(bvn&#......
  • 20240719-CentOS7 ftp服务器搭建与xftp连接
    在CentOS7上搭建ftp服务器,可以使用vsftpd守护进程。安装vsftpd:sudoyuminstall-yvsftpd启动并使vsftpd开机自启:sudosystemctlstartvsftpdsudosystemctlenablevsftpd配置vsftpd编辑配置文件/etc/vsftpd/vsftpd.conf,根据需要修改如下配置:anonymous_enable=NO#禁用......
  • 【专题】2024年中国AIGC行业应用价值研究报告合集PDF分享(附原数据表)
    原文链接:https://tecdat.cn/?p=36570原文出处:拓端数据部落公众号大模型的发展标志着AIGC时代的来临,没有大模型支撑的AI已成为旧时代产物,缺乏竞争力。技术的突破始终是AI发展的关键,而商业应用则是推动其迅速发展的加速器。AI的持久繁荣依赖于其商业化的成功。展望2024年,我们有......