当前位置: 首页 > news >正文

The 2025 ICPC South America - Brazil First Phase

The 2025 ICPC South America - Brazil First Phase

  • L题
  • I题
  • F题

L题

模拟题目

#include <bits/stdc++.h>
using namespace std;
struct WordInfo {int x, y;int order; // 记录在字典中的顺序,用于平局判断!!!
};int main() {ios::sync_with_stdio(false),cin.tie(0),cout.tie(0),cout.tie(0);int n;cin >> n;unordered_map<string, WordInfo> dict;vector<string> dict_order; // 保存字典单词的顺序,用于后续遍历for (int i = 0; i < n; ++i) {string p;int x, y;cin >> p >> x >> y;dict[p] = {x, y, i};dict_order.push_back(p);}int m;cin >> m;vector<string> knowledge_base;int _ = 0;while (_ < m) {string s;cin>>s;knowledge_base.push_back(s);_++;}int Q, win_k;cin >> Q >> win_k;while (Q--) {int file;cin >> file;vector<string> query_words(file);for (int i = 0; i < file; ++i) {cin >> query_words[i];}vector<string> word_need;//符合要求的候选词int current_K = win_k;// 尝试从 current_K 递减到 1,寻找候选词while (current_K >= 1) {vector<string> target_window(query_words.end() - current_K, query_words.end());// 遍历知识库,暴力匹配知识库与窗口中连续且顺序完全一致的位置————按照题目要求//注意:这里knowledge_base.size()要用int强转,否则会有unsigned减到0之下变成大数的bugfor (int i = 0; i < (int)knowledge_base.size() - current_K; ++i) {bool match = true;for (int j = 0; j < current_K; ++j) {if (knowledge_base[i + j] != target_window[j]) {match = false;break;}}if (match) {word_need.push_back(knowledge_base[i + current_K]);}}if (!word_need.empty()) {break;}current_K--;}string ans = "*";if (!word_need.empty()) {long long maxh = -1e18; // 初始化为极小值string best_word;// 将上面从知识库中找到的单词进行比较向量积for (const string& d : dict_order) {auto& d_info = dict[d];long long val = 0;for (const string& ci : word_need) {int ci_x = 0, ci_y = 0;if (dict.count(ci)) {ci_x = dict[ci].x;ci_y = dict[ci].y;}val += (long long)d_info.x * ci_x + (long long)d_info.y * ci_y;// 注意类型转换开long long,防止溢出}if (val > maxh) {maxh = val;best_word = d;}}ans = best_word;}// 输出结果:查询单词 + 预测词for (int i = 0; i < file; ++i) {cout << query_words[i]<<" ";}cout << ans << "\n";}return 0;
}

I题

从后往前缩小范围

#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int N = 1e5 + 5;pii stars[N];
signed main() {int N;cin >> N;for (int i = 0; i < N; i++) {cin >> stars[i].first >> stars[i].second;}vector<int> dist(N - 1);for (int i = 0; i < N - 1; i++) {dist[i] = abs(stars[i].first - stars[i + 1].first) + abs(stars[i].second - stars[i + 1].second);}vector<pii> range(N);range[N - 1] = {1, LLONG_MAX};for (int i = N - 2; i >= 0; i--) {int min_R = dist[i] - range[i + 1].second;int max_R = dist[i] - range[i + 1].first;min_R = max(min_R, 1LL);max_R = min(max_R, dist[i] - 1);// 如果范围无效,则任务不可能完成if (min_R > max_R) {cout << -1 << endl;return 0;}range[i] = {min_R, max_R};}cout << range[0].second << '\n';return 0;
}

作者本来用的二分,但是一直会卡第7个。不知为什么。

#include <iostream>
#include <vector>
#define int long long
using namespace std;
const int N = 2e5 + 5;
int dist[N], n;
bool check(int mid) {int tence = mid;for (int i = 1; i < n; i++) {int t = dist[i] - tence;tence = t;if (t <= 0) {return false;}}return true;
}
signed main() {ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);cin>>n;vector<vector<int>> a(n + 1,vector<int>(2,0));for(int i = 1; i <= n; i++) {cin>>a[i][0]>>a[i][1];}int maxh = 0;for(int i = 2; i <= n; i++) {dist[i - 1] = abs(a[i][0] - a[i - 1][0] + a[i][1] - a[i - 1][1]);maxh = max(maxh, dist[i - 1]);}int l = 1, r = maxh;while (l < r) {int mid = l + (r - l) / 2;if (check(mid)) {l = mid + 1;}else {r = mid;}}if (l == 1) {cout<<-1<<'\n';return 0;}cout<<l - 1<<'\n';return 0;
}

F题

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int N = 1e5 + 5;
int X[N];
ll qmi(ll a, ll b) {ll res = 1;a %= mod;while (b) {if (b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}int main() {ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);ll inv2 = qmi(2, mod - 2);int N, Q;cin >> N >> Q;for (int i = 0; i < Q; i++) {cin >> X[i];}vector<ll> pow2(Q + 2), pow_inv2(Q + 2);//预处理pow2[0] = 1;pow_inv2[0] = 1;for (int i = 1; i <= Q + 1; i++) {pow2[i] = pow2[i - 1] * 2 % mod;pow_inv2[i] = pow_inv2[i - 1] * inv2 % mod;}ll S1 = 0;for (int j = 0; j < Q; j++) {S1 = (S1 + X[j] * pow_inv2[j]) % mod;}vector<ll> S(Q + 2, 0);for (int j = Q - 1; j >= 0; j--) {S[j + 1] = (X[j] * pow_inv2[j + 1] + S[j + 2]) % mod;}vector<vector<int>> table_num(N + 1);for (int t = 1; t <= Q; t++) {table_num[X[t - 1]].push_back(t);}vector<ll> ans(N + 1, 0);for (int i = 1; i <= N; i++) {ll S2 = 0;for (int t : table_num[i]) {S2 = (S2 + pow2[t] * S[t + 1]) % mod;}if (i == 1) {ans[i] = inv2 * (S1 + S2) % mod;} else {ans[i] = inv2 * S2 % mod;}}for (int i = 1; i <= N; i++) {cout << ans[i] << '\n';}return 0;
}
http://www.dtcms.com/a/414542.html

相关文章:

  • 开源 C# 快速开发(六)自定义控件--圆环
  • Calico 网络插件在 K8s 集群的作用
  • 蓝桥杯13届省题
  • 手机网站开发+图库类怎样在手机上建设网站
  • MySQL三层架构:从连接管理到数据存储
  • 嵌入式硬件——IMX6ULL时钟配置
  • 【用androidx.camera拍摄景深合成照片】
  • linux安装google chrome 谷歌浏览器
  • 从零起步学习Redis || 第二章:Cache Aside Pattern(旁路缓存模式)以及优化策略
  • 两性做受技巧视频网站喊别人做的网站不肯给代码
  • ESP32-S3入门第八天:往期知识回顾与实战练习
  • Claude Code 实战指南(三):AI辅助开发工作流 Spec Workflow MCP教程
  • 红帽认证含金量怎么样?适合哪些人?
  • 宣传的网站开发需要多少钱步骤的英文
  • 选择一款拖拽式界面的vscode扩展程序制作Python界面
  • Android开发-屏幕变更事件
  • 十大咨询公司排行榜aso优化师主要是干嘛的
  • LeetCode第1346题 - 检查整数及其两倍数是否存在
  • 【Leetcode hot 100】207.课程表
  • 搜索引擎高级搜索技巧
  • 2.3 物理层设备 (答案见原书 P48)
  • 华为OBS obsutil使用
  • 租购同权七年之痒:政策善意如何变现?
  • 【Linux操作系统】基础开发工具
  • 老年ai模拟恋爱抖音快手微信小程序看广告流量主开源
  • 知名的网站制作公司需要多少钱企业宣传网站模板下载
  • 深圳横岗做网站的网站品牌形象设计怎么做
  • 社区网站推广方案百度百家号注册
  • 编程竞赛高频考点
  • Linux 程序使用 STDOUT 打印日志导致程序“假死”?一次线上 Bug 的深度排查与解决