比赛链接如下:Denso Create Programming Contest 2025(AtCoder Beginner Contest 413) - AtCoder 

A - Content Too Large

Problem Statement
Takahashi has N items and one bag.

The size of the i-th (1≤i≤N) item is Ai​, and the size of the bag is M.

If and only if the total size of the items he is trying to put in the bag is at most M, he can put all those items in the bag simultaneously.

If he can put all N items in the bag simultaneously, print Yes; otherwise, print No.

解题思路:

一次性将N件物品装入大小为M的包中, 能装进去, 输出Yes, 否则, 输出No

#include <bits/stdc++.h>
using namespace std;
void solve() {int n,m;cin>>n>>m;vector<int> a(n);int sum_a=0;for(int i=0;i<n;i++){cin>>a[i];sum_a+=a[i];}if(sum_a<=m){cout<<"Yes"<<'\n';}else{cout<<"No"<<'\n';}
}
int main() {int t=1;// cin >> t;while (t--) {solve();}return 0;
}

 B - cat 2

Problem Statement
You are given N types of strings S1​,S2​,…,SN​.

You perform the following operation once:

Choose distinct integers i and j (1≤i≤N,1≤j≤N) and concatenate Si​ and Sj​ in this order.
How many different strings can be obtained as a result of this operation?

If different choices of (i,j) result in the same concatenated string, it is counted as one string.

解题思路:

将两个下标不同的字符串进行合并, 然后存入到一个set中, 输出set的长度即可 

#include <bits/stdc++.h>
using namespace std;
void solve() {int n;cin >> n;vector<string> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}set<string> st;for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (i == j)continue;st.insert(a[i] + a[j]);}}cout << st.size() << '\n';
}
int main() {int t = 1;// cin >> t;while (t--) {solve();}return 0;
}

 C - Large Queue

Problem Statement
There is an empty integer sequence A=(). You are given Q queries, and you need to process them in the given order. There are two types of queries:

Type 1: Given in the format 1 c x. Add c copies of x to the end of A.
Type 2: Given in the format 2 k. Remove the first k elements from A and output the sum of the removed k integers. It is guaranteed that k is at most the length of A at that time.

    解题思路:

    两种操作, 一种是在A的尾部添加c个x, 另一种是移除A的前k个元素, k的值不能超过A的长度, 同时输出这个k个元素的总和,使用deque维护这个数组A, 然后t=1/2进行操作即可

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using pll = pair<ll, ll>;
    void solve() {int q;cin >> q;deque<pll> dp;while (q--) {int t;cin >> t;if (t == 1) {ll c, x;cin >> c >> x;dp.emplace_back(c, x);} else {ll k;cin >> k;ll sum = 0;while (k > 0 && !dp.empty()) {auto& a = dp.front();ll c = a.first;  ll x = a.second;  if (c <= k) {sum += c * x;k -= c;dp.pop_front();} else {sum += k * x;a.first -= k;k = 0;}}cout << sum << "\n";}}
    }
    int main() {int t=1;// cin>>t;while(t--){solve();}return 0;
    }
    

     D - Make Geometric Sequence

    Problem Statement
    You are given an integer sequence A=(A1​,A2​,…,AN​) of length N. It is guaranteed that for any i (1≤i≤N), Ai​ is not 0.

    Determine whether there exists a permutation B=(B1​,B2​,…,BN​) of A such that B forms a geometric sequence.

    A sequence S=(S1​,S2​,…,SN​) is a geometric sequence if there exists a real number r such that Si+1​=rSi​ for all integers 1≤i<N.

    Solve T test cases per input file.

    解题思路:

    判断数组A的某个排列能否构成等比数列

    1. 数组长度<=2的数列是等比数列

    2. 数组元素相等, 公比q=1

    3. 公比q正负交替的情况(互为相反数)

    => 只有两个值,且互为相反数,数量差不大于1

    4. 一般情况通过 b[i]^2 = b[i-1]*b[i+1]进行判断

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using pll = pair<ll, ll>;
    void solve() {int n;cin >> n;vector<ll> a(n);for (int i = 0; i < n; i++) {cin >> a[i];}if (n <= 2) {cout << "Yes" << '\n';return;}bool f = true;for (int i = 1; i < n; i++) {if (a[i] != a[0]) {f = false;break;}}if (f) {cout << "Yes" << '\n';return;}set<ll> v(a.begin(), a.end());if (v.size() == 2) {auto it = v.begin();ll v1 = *it;it++;ll v2 = *it;if (v1 + v2 == 0) {ll c1 = 0, c2 = 0;for (ll x : a) {if (x == v1)c1++;elsec2++;}if (abs(c1 - c2) <= 1) {cout << "Yes" << '\n';return;}}}sort(a.begin(), a.end(), [](ll x, ll y) { return llabs(x) < llabs(y); });bool f_1 = true;for (int i = 1; i + 1 < n; i++) {ll x = (ll)a[i] * a[i];ll y = (ll)a[i - 1] * a[i + 1];if (x != y) {f_1 = false;break;}}if (f_1)cout << "Yes" << '\n';elsecout << "No" << '\n';
    }
    int main() {int t;cin >> t;while (t--) {solve();}return 0;
    }
    

     E - Reverse 2^i

    Problem Statement
    You are given a permutation P=(P0​,P1​,…,P2N−1​) of (1,2,3,…,2N).

    You can perform the following operation any number of times (possibly zero):

    Choose non-negative integers a,b satisfying 0≤a×2b<(a+1)×2b≤2N, and reverse Pa×2b​,Pa×2b+1​,…,P(a+1)×2b−1​. Here, reversing Pa×2b​,Pa×2b+1​,…,P(a+1)×2b−1​ means simultaneously replacing Pa×2b​,Pa×2b+1​,…,P(a+1)×2b−1​ with P(a+1)×2b−1​,P(a+1)×2b−2​,…,Pa×2b​.
    Find the lexicographically smallest permutation P that can be obtained by repeating the operation.

    You are given T test cases, so find the answer for each.

    解题思路:

    你有一个长度为 2^n 的排列 P,你可以对它做若干次以下操作:

    选择两个整数 a,b,满足区间 [a⋅2^b,(a+1)⋅2^b−1] 在数组范围内,把这个区间反转。

    你要找到经过若干次这种操作后,能得到的字典序最小的排列。

    观察可得:

    每次反转的区间长度必须是 2^b,并且是从 a⋅2^b 开始(即按块划分)。

    实际上这与 对二叉划分结构的左右子树进行翻转是等价的。

    在二叉树的每一级都尝试“原顺序”或“左右块交换”,递归比较返回最小结果

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using pll = pair<ll, ll>;
    vector<ll> dfs(vector<ll>& a, int i, int j) {if (j == 0) {return {a[i]};}auto x = dfs(a, i, j - 1);auto y = dfs(a, i + (1 << (j - 1)), j - 1);vector<ll> m;m.insert(m.end(), x.begin(), x.end());m.insert(m.end(), y.begin(), y.end());vector<ll> t;t.insert(t.end(), y.begin(), y.end());t.insert(t.end(), x.begin(), x.end());if (m <= t) {return m;} else {return t;}
    }
    void solve() {int n;cin >> n;vector<ll> a(1 << n);for (int i = 0; i < (1 << n); i++) {cin >> a[i];}vector<ll> ans = dfs(a, 0, n);for (int i = 0; i < (1 << n); i++) {cout << ans[i];if (i < ans.size() - 1)cout << ' ';elsecout << '\n';}
    }
    int main() {int t;cin >> t;while (t--) {solve();}return 0;
    }
    

     F - No Passag  


    Probl

    em Statement
    There is an H×W grid. Let (i,j) denote the cell at the i-th row from the top and j-th column from the left. Among these, K cells are goals. The i-th goal (1≤i≤K) is cell (Ri​,Ci​).

    Takahashi and Aoki play a game using this grid and a single piece placed on the grid. Takahashi and Aoki repeatedly perform the following series of operations until the piece reaches a goal cell:

    Aoki chooses an integer a between 1 and 4, inclusive.
    Then, Takahashi chooses an integer b between 1 and 4, inclusive, where a=b must be satisfied. Let (i,j) be the cell where the piece is placed before the operation. Based on the chosen integer b and the piece's position, move the piece.
    When b=1: If (i−1,j) is within the grid, move the piece from cell (i,j) to cell (i−1,j); if it is outside the grid, do nothing.
    When b=2: If (i+1,j) is within the grid, move the piece from cell (i,j) to cell (i+1,j); if it is outside the grid, do nothing.
    When b=3: If (i,j−1) is within the grid, move the piece from cell (i,j) to cell (i,j−1); if it is outside the grid, do nothing.
    When b=4: If (i,j+1) is within the grid, move the piece from cell (i,j) to cell (i,j+1); if it is outside the grid, do nothing.
    Takahashi's objective is to minimize the number of moves until the piece reaches a goal. Aoki's objective is to prevent the piece from reaching the goal; if that is impossible, his objective is to maximize the number of moves until the piece reaches a goal.

    For all pairs of integers (i,j) satisfying 1≤i≤H,1≤j≤W, solve the following problem and find the sum of all solutions:

    Start the game with the piece at cell (i,j). Assume both players act optimally toward their respective objectives. If Takahashi can make the piece reach a goal, the solution is the minimum number of moves; otherwise, the solution is 0.

    解题思路:

    1.dp[i] 表示从 i 出发走到目标所需最小步数

    2.用 Dijkstra 从目标反向扩展

    3. Aoki 选 1~4 中一项,Takahashi 从剩下中选最优方向。确保最坏情况最优

    4. 对于每个点,找出在任意 Aoki 决策下,Takahashi 的最小可行步数,再加一更新

    5. 最后,  累加所有的dp[i]

    #include <bits/stdc++.h>
    using namespace std;
    const int INF = 0x3f3f3f3f;
    using pii = pair<int, int>;
    const int dr[5] = {0, -1, 1, 0, 0};
    const int dc[5] = {0, 0, 0, -1, 1};
    void solve() {int H, W, K;cin >> H >> W >> K;vector<int> dp(H * W, INF);vector<char> g(H * W, 0);for (int i = 0; i < K; i++) {int r, c;cin >> r >> c;--r, --c;int id = r * W + c;g[id] = 1;dp[id] = 0;}auto fun = [&](int r, int c) { return r >= 0 && r < H && c >= 0 && c < W; };priority_queue<pii, vector<pii>, greater<>> pq;for (int i = 0; i < H * W; i++) {if (g[i])pq.emplace(0, i);}while (!pq.empty()) {auto [cost, id] = pq.top();pq.pop();if (cost > dp[id])continue;int r = id / W, c = id % W;for (int dir = 1; dir <= 4; dir++) {int nr = r + dr[dir], nc = c + dc[dir];if (!fun(nr, nc))continue;int ni = nr * W + nc;int d[4];for (int i = 0; i < 4; i++) {int ar = nr + dr[i + 1], ac = nc + dc[i + 1];if (fun(ar, ac))d[i] = dp[ar * W + ac];elsed[i] = INF;}int m1 = INF, m2 = INF;for (int i = 0; i < 4; i++) {if (d[i] < m1) {m2 = m1;m1 = d[i];} else if (d[i] < m2) {m2 = d[i];}}int w = 0;for (int i = 0; i < 4; i++) {int k = (d[i] > m1 ? m1 : m2);w = max(w, k);}int c = w >= INF ? INF : w + 1;if (c < dp[ni]) {dp[ni] = c;pq.emplace(c, ni);}}}long long ans = 0;for (int x : dp) {if (x < INF)ans += x;}cout << ans << '\n';
    }
    int main() {solve();return 0;
    }
    

    G - Big Banned Grid

    Problem Statement
    There is an H×W grid. Let (i,j) denote the cell at the i-th row (1≤i≤H) from the top and j-th column (1≤j≤W) from the left.

    Each cell in the grid either has an obstacle placed on it or has nothing placed on it. There are K cells with obstacles: cells (r1​,c1​),(r2​,c2​),…,(rK​,cK​).

    Takahashi is initially at cell (1,1) and wants to reach cell (H,W) by repeatedly moving to an adjacent cell (up, down, left, right) that has nothing placed on it.

    More precisely, he can repeat the following operation as many times as he likes:

    Choose one of the following four operations and perform the chosen operation:
    If 1<i and cell (i−1,j) has nothing placed on it, move to cell (i−1,j). Otherwise, do not move.
    If 1<j and cell (i,j−1) has nothing placed on it, move to cell (i,j−1). Otherwise, do not move.
    If i<H and cell (i+1,j) has nothing placed on it, move to cell (i+1,j). Otherwise, do not move.
    If j<W and cell (i,j+1) has nothing placed on it, move to cell (i,j+1). Otherwise, do not move.
    Determine whether he can move from cell (1,1) to cell (H,W).

    解题思路:

    如果有一条线能将(1,1)和(H,W)在网格中分割成两个独立的块, 两点就无法形成通路

    实现上, 我们可以, 

    为四个边界创建虚拟节点(编号k到k+3):

    k:上边界(x=1)

    k+1:下边界(x=n)

    k+2:左边界(y=1)

    k+3:右边界(y=m)

    如果障碍物在边界上,将其与对应虚拟节点合并

    遍历每个障碍物,检查它的8个方向(上下左右+对角线)

    如果邻域存在其他障碍物,合并它们的集合

    最后, 如果存在下面四种情况就说明两点被隔断了

    上边界和下边界连通(k和k+1)

    上边界和左边界连通(k和k+2)

    左边界和右边界连通(k+2和k+3)

    下边界和右边界连通(k+1和k+3)

    #include <bits/stdc++.h>
    using namespace std;
    class UnionFind {vector<int> fa, sz;
    public:int cc;UnionFind(int n) : fa(n), sz(n, 1), cc(n) { iota(fa.begin(), fa.end(), 0); }int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }bool merge(int x, int y) {x = find(x), y = find(y);if (x == y)return false;if (sz[x] > sz[y])swap(x, y);fa[x] = y;sz[y] += sz[x];cc--;return true;}
    };
    void solve() {int n, m, k;cin >> n >> m >> k;map<pair<int, int>, int> mp;vector<pair<int, int>> p(k);UnionFind uf(k + 5);for (int i = 0; i < k; i++) {cin >> p[i].first >> p[i].second;mp[p[i]] = i;if (p[i].first == 1)uf.merge(i, k);if (p[i].first == n)uf.merge(i, k + 1);if (p[i].second == 1)uf.merge(i, k + 2);if (p[i].second == m)uf.merge(i, k + 3);}for (int i = 0; i < k; i++) {int x = p[i].first, y = p[i].second;for (int dx = -1; dx <= 1; dx++) {for (int dy = -1; dy <= 1; dy++) {if (dx == 0 && dy == 0)continue;auto it = mp.find({x + dx, y + dy});if (it != mp.end()) {uf.merge(i, it->second);}}}}bool ans = uf.find(k) == uf.find(k + 1) || uf.find(k) == uf.find(k + 2) ||uf.find(k + 2) == uf.find(k + 3) ||uf.find(k + 1) == uf.find(k + 3);cout << (ans ? "No" : "Yes") << '\n';
    }
    int main() {solve();return 0;
    }

     感谢大家的点赞和关注,你们的支持是我创作的动力!

     

    本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
    如若转载,请注明出处:http://www.pswp.cn/news/913850.shtml
    繁体地址,请注明出处:http://hk.pswp.cn/news/913850.shtml
    英文地址,请注明出处:http://en.pswp.cn/news/913850.shtml

    如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

    相关文章

    Java学习---JVM(1)

    JVM&#xff0c;即Java虚拟机&#xff0c;其是Java程序的运行环境&#xff0c;是Java技术的核心组成部分&#xff0c;本次就JVM的自动内存管理详细展开&#xff1a;JVM的内存区域分为2大类&#xff0c;即线程私有的和线程共享的&#xff0c;前者分为3大块&#xff0c;虚拟机栈、…

    Qt去噪面板搭建

    建立单选互斥性面板用于选择噪声属性// 创建去噪面板 QWidget* noisePanel new QWidget(); QVBoxLayout* mainLayout new QVBoxLayout(noisePanel); mainLayout->setContentsMargins(10, 10, 10, 10); mainLayout->setSpacing(15);// 去噪方法选择组QGroupBox* methodG…

    无需公网IP的文件交互:FileCodeBox容器化部署技术解析

    文章目录 前言1.Docker部署2.简单使用演示3. 安装cpolar内网穿透4. 配置公网地址5. 配置固定公网地址 前言 在数字化办公需求日益增长的今天&#xff0c;文件传输已成为职场协作的高频刚需。传统共享方式却饱受诟病&#xff1a;"需要安装哪些臃肿客户端&#xff1f;免费版…

    1. http 有哪些版本,你是用的哪个版本,怎么查看

    http 有哪些版本&#xff0c;你是用的哪个版本&#xff0c;怎么查看 总结&#xff1a;http 版本有 0.9/1.0/1.1/2.0/3.0&#xff0c;我们常用的是 1.1 和 2.0&#xff0c;使用 window.chrome.loadTimes() 获取 http 版本。 常见的 HTTP 版本 HTTP/0.9&#xff1a;最初的版本&am…

    C# IIncrementalGenerator干点啥

    生成器项目 得基于.Net Stander 2.0 重要&#xff1a;<IsRoslynComponent>true</IsRoslynComponent>、<IncludeBuildOutput>false</IncludeBuildOutput>、 <PackageReference Include"Microsoft.CodeAnalysis" Version"4.14.0&q…

    在徐州网络中服务器租用与托管的优势

    一、高性价比&#xff1a;徐州万恒提供多种配置的服务器供租用&#xff0c;满足不同企业和个人的业务需求&#xff0c;无论是初创企业追求低成本高效能&#xff0c;还是对性能有严苛要求的大型项目&#xff0c;都能找到合适的服务器型号&#xff0c;以极具竞争力的价格获取强大…

    学习软件测试的第十四天(移动端)

    一.常用的abd命令有哪些1.什么是 ADB&#xff1f;通俗解释&#xff1a; ADB 就像一个桥梁&#xff0c;让电脑能控制连接的手机&#xff0c;比如安装APP、抓日志、重启设备等。专业术语总结&#xff1a; ADB&#xff08;Android Debug Bridge&#xff09;是 Android SDK 提供的命…

    04-ES6

    let和const命令ES6中新增了let命令&#xff0c;用来声明变量&#xff0c;用法类似与varlet和var的不同&#xff1a;1、不存在变量提升 console.log(a); //Cannot access a before initializationlet a 100;2、同一个作用域不能重复定义同一个名称var c 20;let c 30;c…

    基于GeographicLib实现测站地平坐标系(东北天)转地心固定坐标系XYZ

    一、概述主要内容&#xff1a;本文基于GeographicLib开源库&#xff0c;实现了一个地理空间坐标转换功能&#xff0c;主要用于根据观测站的位置和目标的相对方位信息&#xff0c;计算目标在地球坐标系中的绝对位置。输入&#xff1a;观测站的经纬度坐标(纬度、经度、海拔高度)和…

    若依框架去掉Redis

    这篇文章全是按照我的实战操作来的&#xff0c;本文一是记录一下这个过程&#xff0c;二是帮助更多的人少走弯路。 接下来我们看实战&#xff1a;第一步毋庸置疑&#xff0c;就是找到配置文件application.yml里面大redis配置部分&#xff0c;直接注释掉 注意这里的data:这是否注…

    【会员专享数据】2013-2024年我国省市县三级逐日SO₂数值数据(Shp/Excel格式)

    之前我们分享过2013-2024年全国范围逐日SO₂栅格数据&#xff08;可查看之前的文章获悉详情&#xff09;!该数据来源于韦晶博士、李占清教授团队发布在国家青藏高原科学数据中心网站上的中国高分辨率高质量近地表空气污染物数据集。很多小伙伴拿到数据后反馈栅格数据不太方便使…

    TCP SYN、UDP、ICMP之DOS攻击

    一、实验背景 Dos攻击是指故意的攻击网络协议实现的缺陷或直接通过野蛮手段残忍地耗尽被攻击对象的资源&#xff0c;目的是让目标计算机或网络无法提供正常的服务或资源访问&#xff0c;使目标系统服务系统停止响应甚至崩溃。 二、实验设备 1.一台靶机Windows主机 2.增加一个网…

    Ntfs!LfsUpdateLfcbFromRestart函数分析之根据Ntfs!_LFS_RESTART_AREA初始化Ntfs!_LFCB

    第一部分&#xff1a;LfsUpdateLfcbFromRestart( ThisLfcb,FileSize,DiskRestartArea,FirstRestar1: kd> p Ntfs!LfsRestartLogFile0x317: f71fc8dd e820e5ffff call Ntfs!LfsUpdateLfcbFromRestart (f71fae02) 1: kd> t Ntfs!LfsUpdateLfcbFromRestart: f71fae0…

    Qt开发:QtConcurrent介绍和使用

    文章目录一、QtConcurrent 简介二、常用功能分类2.1 异步运行一个函数&#xff08;无返回值&#xff09;2.2 异步运行一个带参数的函数&#xff08;有返回值&#xff09;2.3 绑定类成员函数2.4 容器并行处理&#xff08;map&#xff09;三、线程池控制四、取消任务五、典型应用…

    企业数据开发治理平台选型:13款系统优劣对比

    本文将深入对比13款主流的数据指标管理平台&#xff1a;1.网易数帆&#xff1b; 2.云徙科技&#xff1b; 3.数澜科技&#xff1b; 4.用友数据中台&#xff1b; 5.龙石数据中台&#xff1b; 6.SelectDB&#xff1b; 7.得帆云 DeHoop 数据中台&#xff1b; 8.Talend&#xff1b; …

    Java JDK 下载指南

    Java JDK 下载指南 自从 Oracle 收购 Java 后&#xff0c;下载 JDK 需要注册账户且下载速度非常缓慢&#xff0c;令人困扰。 解决方案&#xff1a; 华为云提供了便捷的 JDK 下载镜像&#xff0c;访问速度快且无需注册&#xff1a; https://repo.huaweicloud.com/java/jdk/ 高…

    QT数据交互全解析:JSON处理与HTTP通信

    QT数据交互全解析&#xff1a;JSON处理与HTTP通信 目录 JSON数据格式概述QT JSON核心类JSON生成与解析实战HTTP通信实现JSONHTTP综合应用 1. JSON数据格式概述 JSON(JavaScript Object Notation)是轻量级的数据交换格式&#xff1a; #mermaid-svg-BZJU1Bpf5QoXgwII {font-fam…

    Function Call大模型的理解(大白话版本)

    由来---场景设计你雇了一位 超级聪明的百科全书管家&#xff08;就是大模型&#xff0c;比如GPT&#xff09;。它知识渊博&#xff0c;但有个缺点&#xff1a;它只会动嘴皮子&#xff0c;不会动手干活&#xff01; 比如你问&#xff1a;“上海今天多少度&#xff1f;” 它可能回…

    【PTA数据结构 | C语言版】求两个正整数的最大公约数

    本专栏持续输出数据结构题目集&#xff0c;欢迎订阅。 文章目录题目代码题目 请编写程序&#xff0c;求两个正整数的最大公约数。 输入格式&#xff1a; 输入在一行中给出一对正整数 0<x,y≤10^6&#xff0c;数字间以空格分隔。 输出格式&#xff1a; 在一行中输出 x 和 …

    Linux下LCD驱动-IMX6ULL

    一.Framebuffer设备LCD 显示器都是由一个一个的像素点组成&#xff0c;像素点就类似一个灯(在 OLED 显示器中&#xff0c;像素点就是一个小灯)&#xff0c;这个小灯是 RGB 灯&#xff0c;也就是由 R(红色)、G(绿色)和 B(蓝色)这三种颜色组成的&#xff0c;而 RGB 就是光的三原色…