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

Educational Codeforces Round 184 (Rated for Div. 2)(A-D1)

题目链接Educational Codeforces Round 184 (Rated for Div. 2)

A.Alice and Bob

思路

贪心,以a为分界点,如果左边的元素多余右边的就输出a - 1,否则输出a + 1,注意等于a的元素要忽略不计,赛时这里wa了一发

代码

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << "=" << x << '\n';
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a));
#define int long long
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;void solve() {int n, x;cin >> n >> x;vector<int> a(n);for (int i = 0; i < n; i++) cin >> a[i];sort(a.begin(), a.end());int t = 0;while (t < n && a[t] < x) {t++;}int m = n;for (int i = t; i < n; i++) {if (a[i] == x) m--;}if (t > m - t) {cout << x - 1 << endl;return;}else if (t <= n - t) {cout << x + 1 << endl;return;}return;
}signed main() {ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);int T = 1;cin >> T;while (T--) solve();return 0;
}

B.Drifting Away

思路

依旧贪心加模拟,能到达岸边的情况很少,依次枚举即可,需注意的是当是<<<*>>>这种类型时也可以到达岸边,赛事被这个卡了1个小时,呜呜呜,导致C题赛后5分钟才提交通过,痛

代码

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << "=" << x << '\n';
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a));
#define int long long
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;void solve() {string s;cin >> s;int n = s.size();if (n == 1) {cout << 1 << endl;return;}int l = 0, r = n - 1;if (s[0] == '*') {for (int i = 1; i < n; i++) {if (s[i] != '>') {cout << -1 << endl;return;}}cout << n << endl;return;}else if (s[0] == '>') {for (int i = 0; i < n; i++) {if (s[i] != '>') {cout << -1 << endl;return;}}cout << n << endl;return;}else {while (l + 1 < n && s[l + 1] == '<') {l++;}}if (s[n - 1] == '*') {for (int i = n - 2; i >= 0; i--) {if(s[i] != '<') {cout << -1 << endl;return;}}cout << n << endl;return;}else if (s[n - 1] == '<') {for (int i = 0; i < n; i++) {if (s[i] != '<') {cout << -1 << endl;return;}}cout << n << endl;return;}else {while (r - 1 >= 0 && s[r - 1] == '>') {r--;}}if (l + 1 == r) {cout << max(l + 1, n - r) << endl;return;}else if (r - l == 2 && s[l + 1] == '*') {int ans = max(l + 1, n - r) + 1;cout << ans << endl;return;}cout << -1 << endl;return;
}signed main() {ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);int T = 1;cin >> T;while (T--) solve();return 0;
}

C.Range Operation

思路

用到了数学思维,用数组p表示数组的前缀和,根据题目要求就是要
(l + r) * (r - l + 1) - (p[r] - p[l - 1])最大,那么就将该式子转换成求
(r * r + r - p[r]) + (l - l * l + p[l - 1])的最大值,两部分分开依次求最大值,需要注意的是r>=l,就因为我把这部分一开始给忽略了,导致赛时没ac,赛后5分钟才成功ac

代码

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << "=" << x << '\n';
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a));
#define int long long
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int N = 1e18 + 5;void solve() {int n;cin >> n;vector<int> p(n + 1, 0);vector<int> a(n + 1);int ans = 0;for (int i = 1; i <= n; i++) {cin >> a[i];ans += a[i];p[i] = p[i - 1] + a[i];}int mx = -N;vector<int> f(n + 1, -N), g(n + 1, -N);for (int i = 1; i <= n; i++) {int t = i * i + i - p[i];g[i] = t;int y = i - i * i + p[i - 1];f[i] = max(f[i - 1], y);}int sum = 0;for (int i = 1; i <= n; i++) {int t = g[i] + f[i];sum = max(t, sum);}ans += sum;cout << ans << endl;return;
}signed main() {ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);int T = 1;cin >> T;while (T--) solve();return 0;
}

D1.Removal of a Sequence (Easy Version)

思路

二分答案,注意要答案要尽量小

代码

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using u32 = unsigned;
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << "=" << x << '\n';
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a));
#define int long long
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int N = 1e12;int x, y, k;int check(int mid) {for (int i = 1; i <= x; i++) {mid -= mid / y;}return mid;
}void solve() {cin >> x >> y >> k;if (k < y) {cout << k << endl;return;}int ans = -1;int l = 1, r = N;while (l <= r) {int mid = (l + r) >> 1;if (check(mid) >= k) {ans = mid;r = mid - 1;//往更小的满足条件的找}else {l = mid + 1;}}cout << ans << endl;return;
}signed main() {ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);int T = 1;cin >> T;while (T--) solve();return 0;
}

D2.Removal of a Sequence (Hard Version)

补充

等我之后补

http://www.dtcms.com/a/614736.html

相关文章:

  • 网站建设期间工作代理网址是什么意思
  • 树莓派连接 DS3231 时钟模块
  • 深入理解MySQL:体系结构与SQL语句执行流程
  • 【C/数据结构】单链表
  • 添加mysql备份工具Workbench
  • 外贸买家网站建设公司网站的步骤
  • 网站怎么做排查修复wordpress金融
  • Multi-clues adaptive learning for Cloth-Changing Person Re-Identification 解读
  • 【工具】内网渗透神器cs使用
  • 零样本学习(Zero-Shot Learning)详细说明
  • 厦门网站建设有哪些公司赣州星亚网络传媒有限公司
  • 建立网站项目深圳市中心在哪个位置
  • 数据治理进阶——解读数据治理基础知识培训【附全文阅读】
  • 建立自己网站的好处wordpress自定义页
  • 朝阳企业网站建设方案费用wordpress排行榜
  • 基于HRNet与选择性特征变换的深度网络优化研究
  • 【完整源码+数据集】海洋生物数据集,yolov8水下生物检测数据集 7507 张,海洋动物识别数据集,海洋巡检海底生物识别系统实战教程
  • 一般做网站费用农业推广作业
  • 外国优秀网站欣赏网站建设维护合同范本
  • 【概念科普】原位CT(In-situ CT)技术详解:从定义到应用的系统梳理
  • ModbusRtu读取和写入一个寄存器示例
  • 电商网站商品表设计方案如何找网站做推广
  • Linux 34TCP服务器多进程并发
  • 网站建设找谁好深圳聘请做网站人员
  • C语言编译器Visual Studio | 高效开发与调试工具
  • 滨海新区建设和交通局网站一个人建设小型网站
  • Java 8 Lambda表达式详解
  • vip视频解析网站怎么做离石古楼角网站建设
  • DVL数据协议深度解析:PD0、PD4、PD6格式详解与实践应用
  • Web自动化测试详细流程和步骤