VP Codeforces Round 944 (Div 4)

embedded/2024/9/25 10:29:29/

感受:

A~G 其实都不难,都可以试着补起来。 H看到矩阵就放弃了。

A题:

思路:

打开编译器

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e8;
inline void solve() {int a, b; cin >> a >> b;if (a > b) swap(a, b);cout << a << ' ' << b << endl;
}
signed main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);int tt; cin >> tt;while (tt -- ) solve();return 0;
}

B题:

思路:

 思维一点。如果这个字符串不是全都一样的话,那么一定就是输出Yes的,具体在实现。如果在后面遇到过与开头不一样的字符,我们进行交换输出即可。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
const int N = 1e8;
inline void solve() {string a; cin >> a;if (a.size() == 1) return cout << "NO\n", void();char c = a[0];for (int i = 1; i < a.size(); i ++ ) {if (a[i] != c) {swap(a[i], a[0]);cout << "YES" << endl;cout << a << endl;return;}}cout << "NO" << endl;
}
signed main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);int tt; cin >> tt;while (tt -- ) solve();return 0;
}

C题:

思路:

要判断是否相交,即要满足以下条件:(假设我们已经排好序)

1.第一条线段的开头小于第二条线段的开头

2.第一条线段的末尾大于第二条线段的开头

3.第二条线段的末尾大于第一条线段的末尾

排序过程可以想象成将12-1这段拆开来,将环变成线段。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;
const int N = 1e8;
inline void solve() {PII a, b;cin >> a.x >> a.y;cin >> b.x >> b.y;if (a.x > a.y) swap(a.x, a.y);if (b.x > b.y) swap(b.x, b.y);if (a > b) swap(a, b);if (a.x < b.x && b.x < a.y && a.y < b.y) cout << "YES\n";else cout << "NO\n";
}
signed main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);int tt; cin >> tt;while (tt -- ) solve();return 0;
}

 D题:

思路:

我们要尽可能少剪,那么可能是剪一连串的0或者1.

然后我们进行分类讨论

如果开头是0,有0001111这样子的子串,我们是不是还可以少剪一个?

如果开头是1,有1100111这样子的子串,我们还可以少剪一个。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define x first
#define y secondusing namespace std;
typedef pair<int, int> PII;
const int N = 1e8;inline void solve() {string a; cin >> a;int n = a.size();if (n == 1) return cout << 1 << endl, void();// 001001001int cnt = 1;for (int i = 1; i < n; i ++ ) {if (a[i] != a[i - 1]) cnt += 1;}if (a[0] == '0') {cout << (cnt > 1 ? cnt - 1 : 1) << endl;}else {cout << (cnt > 2 ? cnt - 1 : cnt) << endl;}
}signed main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);int tt; cin >> tt;while (tt -- ) solve();return 0;
}

E题:

思路:

速度是匀速的,主要问题是确定在哪段,我们直接二分即可。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define x first
#define y secondusing namespace std;
typedef pair<int, int> PII;
const int N = 1e8;inline void solve() {int n, k, q; cin >> n >> k >> q;vector<PII> a(k + 2);a[1].first = a[1].second = 0;for (int i = 2; i <= k + 1; i ++ ) cin >> a[i].first;for (int i = 2; i <= k + 1; i ++ ) cin >> a[i].second;while (q -- ) {int x; cin >> x;int l = 1, r = k + 2;while (l + 1 != r) {int mid = (l + r) >> 1;if (a[mid].first < x) l = mid;else r = mid;}int len = a[r].second - a[l].second;int d = a[r].first - a[l].first;int t = x - a[l].first;int ans = a[l].second + t * len / d;cout << ans << ' ';}cout << endl;
}signed main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);int tt; cin >> tt;while (tt -- ) solve();return 0;
}

F题: 

思路:

饶有兴趣的是,它是r的总和小于1e5.

所以我们可以直接枚举 x。

那么我们为什么要枚举 x 呢?

因为当我们移动 x 的时候,y的值也在进行变动

x^{2} + y^{2} = r ^{2}

y的值即可以用二分求出来了。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
#define x first
#define y secondusing namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 9;
inline int fac(int t) {int ans = 0;for (int x = 0; x < t; x ++ ) {int now = t * t - x * x;int l = -1, r = t;while (l + 1 != r) {int mid = (l + r) >> 1;if (mid * mid < now) l = mid;else r = mid;}ans += r;}return ans;
}inline void solve() {int r; cin >> r;int ans = fac(r + 1) - fac(r);ans *= 4;ans -= 4;cout << ans << endl;
}
inline void pre_work() {}signed main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);pre_work();int tt; cin >> tt;while (tt -- ) solve();return 0;
}

G题:

思路:

一个数 x 跟哪些数异或起来会小于等于3?

答案是 x, x ^ 1, x ^ 2, x ^ 3

因为二进制从第三位开始就必须要一模一样了。

交换可以用map存数量,用的时候减去即可。

代码:

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define int long long
#define x first
#define y secondusing namespace std;
typedef pair<int, int> PII;
const int N = 1e5 + 9;inline void solve() {int n; cin >> n;vector<int> a(n + 1);map<int, int> cnt;for (int i = 1; i <= n; i ++ ) {cin >> a[i];cnt[a[i]] += 1;}for (int i = 1; i <= n; i ++ ) {int b[4];b[0] = a[i], b[1] = a[i] ^ 1, b[2] = a[i] ^ 2, b[3] = a[i] ^ 3;sort(b, b + 4);for (int j = 0; j < 4; j ++ ) {if (cnt[b[j]]) {cout << b[j] << ' ';cnt[b[j]] -= 1;break;}}}cout << endl;
}
inline void pre_work() {}signed main() {ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);pre_work();int tt; cin >> tt;while (tt -- ) solve();return 0;
}


http://www.ppmy.cn/embedded/41544.html

相关文章

【全志】【Android 11】Android Studio 调试系统APP:实现Platform自动签名

文章目录 一、前言二、预备知识三、如何查看APK签名?3.1 签名错误导致安装失败3.2 签名正确3.3 使用keytool查看签名数据四、使用AS进行签名的条件五、制作JKS文件六、配置AS进行自动签名七、AS签名APK方式一:build直接产生已签名文件方式二:使用singed工具八、运行一、前言…

xfce4使用Alt+鼠标滚轮 放大或缩小桌面

在浏览网页的时候&#xff0c;想缩小网页&#xff0c;结果不小心使用Alt鼠标滚轮向前滚动&#xff0c;放大了桌面&#xff0c;得到了超大的桌面&#xff0c;当然因为显示器没有变大&#xff0c;所以操作起来非常不方便。幸好后来又用Alt鼠标滚轮向后滚动&#xff0c;把桌面恢复…

ElasticSearch详解

ElasticSearch详解&#xff1a;深入探索分布式搜索与分析引擎 一、引言 在当今大数据和云计算的时代&#xff0c;数据的处理和分析能力已成为企业竞争力的关键。ElasticSearch&#xff0c;作为一款基于Lucene构建的开源、分布式、RESTful搜索和分析引擎&#xff0c;以其强大的…

在MyBatis中,如何将数据库中的字符串类型映射为枚举类型?

在MyBatis中&#xff0c;如何将数据库中的字符串类型映射为枚举类型&#xff1f; 网上看了很多教程。说了很多&#xff0c;但是都没说到重点&#xff01; 很简单&#xff0c;xml文件中&#xff0c; 使用resultType&#xff0c;而不是使用resultMap就可以了。 resultType"…

微信小程序使用过程注意事项

整个页面的样式设置&#xff1f; 全局页面和单个页面设置整个页面的样式时都可以通过 page标签选择器来设置。 page {background:red; }给轮播图swiper设置圆角&#xff0c;使用border-radius:10rpx;不生效? 需要再加上overflow:hidden. swiper {border-radius: 10rpx;overflo…

SharePoint 使用renderListDataAsStream方法查询list超过5000时的数据

问题&#xff1a; 当SharePoint List里的数据超过5000时&#xff0c;如果使用常用的rest api去获取数据&#xff0c;例如 await this.sp.web.lists.getByTitle(Document Library).rootFolder.files.select(*, listItemAllFields).expand(listItemAllFields).filter(listItemA…

开源模型应用落地-CodeQwen模型小试-集成langchain(四)

一、前言 通过学习代码专家模型&#xff0c;开发人员可以获得高效、准确和个性化的代码支持。这不仅可以提高工作效率&#xff0c;还可以在不同的技术环境中简化软件开发工作流程。代码专家模型的引入将为开发人员带来更多的机会去关注创造性的编程任务&#xff0c;从而推动软件…

go语言中的数组和切片

Go语言中的数组和切片 数组 定义 一维数组 一维数组是具有相同数据类型的固定大小的数据序列。在Go语言中&#xff0c;一维数组的定义形式为var arrayName [size]dataType&#xff0c;其中arrayName是数组的名称&#xff0c;size是数组的大小&#xff0c;dataType是数组中元…