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

codeforce round951 div2

A guess the maximum

问题:

翻译一下就是求所有相邻元素中max - 1的最小值

代码:

#include <iostream>
#include <algorithm>using namespace std;const int N = 5e4;int a[N];
int n;void solve() {cin >> n;int ans = 0x3f3f3f3f;for(int i = 1; i <= n; i ++ ) cin >> a[i];for(int i = 1; i <= n - 1; i ++ ) {int k = max(a[i], a[i + 1]) - 1;ans = min(ans, k);}cout << ans << endl;
}int main() {int t;cin >> t;while(t -- ) {solve();}return 0;
}

B Xor sequences

题目:

思路:guess题,就是求两个数的lowbit

代码:

#include <iostream>
#include <algorithm>using namespace std;const int N = 5e4;int a[N];
int n;void solve() {int x, y;cin >> x >> y;int ans = 1;for(int i = 0; i <= 30; i ++ ) {int xx = x >> i & 1;int yy = y >> i & 1;if(xx == yy) ans *= 2;else break;}cout << ans << endl;
}int main() {int t;cin >> t;while(t -- ) {solve();}return 0;
}

C earning on bets

题目:

思路:

以下为不严谨证明

假设有n = 3 

k1 k2 k3

x1 x2 x3

满足x1 * k1 > x1 + x2 + x3

        x2 * k2 > x1 + x2 + x3

        x3 * k3 > x1 + x2 + x3

变形后有sigma 1/k < 1

由于分数的精度不好计算,因此考虑乘上所有k的lcm

即 lcm * sigma 1/k < lcm

这个是判断条件,如果成立给每个1/k乘上lcm即可

代码:

#include <iostream>using namespace std;const int N = 2e5 + 10;int k[N];int _gcd(int a, int b) {return b? _gcd(b, a % b): a;
}int lcm(int a, int b) {return a * b / _gcd(a, b);
}void solve() {int n;cin >> n;for(int i = 1; i <= n; i ++ ) cin >> k[i];int L = 1;for(int i = 1; i <= n; i ++ ) {L = lcm(L, k[i]);} int sum = 0;for(int i = 1; i <= n; i ++ ) {sum += L / k[i];}if(sum >= L) cout << -1;else for(int i = 1; i <= n; i ++ ) {cout << L / k[i] << " ";}
}int main() {int t;cin >> t;while( t-- ) {solve();}
}

D fixing a binary string

题目:

思路:对原操作进行化简,实际上就是把前p个字符翻转,并且接到原字符串的后面,则此时我们的答案串实际上是已知的如果第p个字符是1,那么答案串就是以1结尾的k pop串,反之则是以0

结尾的k pop串,既然答案已知我们遍考虑枚举p,之后在o1内用哈希字符串比较。注意到还要对原串翻转,因此还要倒着求一遍哈希

这题没有卡哈希

代码:

#include <iostream>
#include <algorithm>using namespace std;const int N = 2e5 + 10;
const int P = 131;typedef unsigned long long ULL;int n, k;
char s[N], str[N];
ULL ansh[N], h[N], p[N], reh[N];
/*
re (n - p + 1 , n) == ans (n - p + 1, n);
h p + 1, n == ans 1, n - p
*/
bool check(int x) {if(reh[n] - reh[n - x] * p[x] == ansh[n] - ansh[n - x] * p[x]) {if(h[n] - h[x] * p[n - x] == ansh[n - x] - ansh[0] * p[n - x]) {return true;}       }return false;
}void solve() {cin >> n >> k;for(int i = 1; i <= n; i ++ ) cin >> s[i];p[0] =  1;int c = s[1] - '0';for(int i = n, cnt = 1, judge = 1; i; i --, judge ++ ) {if(cnt & 1) str[i] = c + '0';else str[i] = !c + '0';if(judge % k == 0) cnt ++;}for(int i = 1; i <= n; i ++ ) p[i] = p[i - 1] * P;for(int i = 1; i <= n; i ++ ) h[i] = h[i - 1] * P + s[i];for(int i = 1; i <= n; i ++ ) ansh[i] = ansh[i - 1] * P + str[i];reverse(s + 1, s + n + 1);for(int i = 1; i <= n; i ++ ) reh[i] = reh[i - 1] * P + s[i];for(int i = 1; i <= n; i ++ ) {if(check(i)) {cout << i << endl;return;}}cout << -1 << endl;
}int main() {int t;cin >> t;while(t -- ) {solve();}return 0;
}

http://www.lryc.cn/news/368733.html

相关文章:

  • arcgis开发记录
  • RPA-UiBot6.0数据整理机器人—杂乱数据秒变报表
  • Application UI
  • 关于 Redis 中集群
  • C++必修:探索C++的内存管理
  • python列表---基本语法(浅拷贝,深拷贝等)
  • go语言接口之sort.Interface接口
  • android:text 总为大写字母的原因
  • CISCN2024 初赛 wp 部分复现(Re)
  • YOLOv10、YOLOv9 和 YOLOv8 在实际视频中的对比
  • 热题系列章节5
  • ArcGIS for js 4.x 加载图层
  • Three.js和Babylon.js,webGL中的对比效果分析!
  • flask实现抽奖程序(一)
  • Python中数据库连接的管理
  • 【JAVA技术】mybatis 数据库敏感字段加解密方案
  • Collections工具类及其案例
  • Duck Bro的第512天创作纪念日
  • 【机器学习】GPT-4中的机器学习如何塑造人类与AI的新对话
  • 晨控CK-UR12-E01与欧姆龙NX/NJ系列EtherNet/IP通讯手册
  • 模板显式、隐式实例化和(偏)特化、具体化的详细分析
  • 软件设计师笔记-计算机系统基础知识
  • flink 作业动态维护更新,不重启flink,不提交作业
  • 为何数据仓库需要“分层次”?
  • 小熊家务帮day15-day18 预约下单模块(预约下单,熔断降级,支付功能,退款功能)
  • [word] word悬挂缩进怎么设置? #经验分享#职场发展#经验分享
  • 6-Maven的使用
  • WPF真入门教程32--WPF数字大屏项目实干
  • 数据可视化Python实现超详解【数据分析】
  • Maxkb玩转大语言模型