Codeforces Round #562 (Div. 2) C. Increasing by Modulo
链接:https://codeforces.com/contest/1169/problem/C
题意:
Toad Zitz has an array of integers, each integer is between 00 and m−1m−1 inclusive. The integers are a1,a2,…,ana1,a2,…,an.
In one operation Zitz can choose an integer kk and kk indices i1,i2,…,iki1,i2,…,ik such that 1≤i1<i2<…<ik≤n1≤i1<i2<…<ik≤n. He should then change aijaij to ((aij+1)modm)((aij+1)modm) for each chosen integer ijij. The integer mm is fixed for all operations and indices.
Here xmodyxmody denotes the remainder of the division of xx by yy.
Zitz wants to make his array non-decreasing with the minimum number of such operations. Find this minimum number of operations.
思路:
二分,考虑当前步数能否满足条件即可。判断时候,如果ai+1 < ai 则判断能否使ai加到ai+1,如果不行则当前步数不行,如果ai+1 > ai。同样尽量使ai+1 = ai,如果不行并不结束。
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
int a[MAXN]; bool Check(int cnt)
{
int temp = 0;
for (int i = 1;i <= n;i++)
{
if (a[i] < temp)
{
int ops = temp-a[i];
if (ops > cnt)
return false;
}
else if (a[i] > temp)
{
int ops = m-a[i]+temp;
if (ops > cnt)
temp = a[i];
}
}
return true;
} int main()
{
cin >> n >> m;
for (int i = 1;i <= n;i++)
cin >> a[i];
int l = 0, r = m;
int res = m;
while (l < r)
{
int mid = (l+r)/2;
if (Check(mid))
{
res = min(res, mid);
r = mid;
}
else
l = mid+1;
}
cout << res << endl; return 0;
}
Codeforces Round #562 (Div. 2) C. Increasing by Modulo的更多相关文章
- [Done] Codeforces Round #562 (Div. 2) 题解
A - Circle Metro 模拟几百步就可以了. B - Pairs 爆搜一下,时间复杂度大概是 $O(4 * n)$ Code: 56306723 C - Increasing by Modu ...
- Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version)【模拟】
一 题面 C2. Increasing Subsequence (hard version) 二 分析 需要思考清楚再写的一个题目,不能一看题目就上手,容易写错. 分以下几种情况: 1 左右两端数都小 ...
- Codeforces Round #562 (Div. 2) B. Pairs
链接:https://codeforces.com/contest/1169/problem/B 题意: Toad Ivan has mm pairs of integers, each intege ...
- Codeforces Round #562 (Div. 2) A.Circle Metro
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...
- Codeforces Round #555 (Div. 3) C2. Increasing Subsequence (hard version) (贪心)
题意:给你一组数,每次可以选队首或队尾的数放入栈中,栈中元素必须保持严格单增,问栈中最多能有多少元素,并输出选择情况. 题解:首先考虑队首和队尾元素不相等的情况,如果两个数都大于栈顶元素,那么我们选小 ...
- Codeforces Round #534 (Div. 2) D. Game with modulo(取余性质+二分)
D. Game with modulo 题目链接:https://codeforces.com/contest/1104/problem/D 题意: 这题是一个交互题,首先一开始会有一个数a,你最终的 ...
- Codeforces Round #534 (Div. 2) D. Game with modulo 交互题
先二分一个区间,再在区间里面二分即可: 可以仔细想想,想明白很有意思的: #include<iostream> #include<cstdio> #include<alg ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- html中css的三种样式
在html中定义CSS样式的方法有三种,新建CSS文件 使用link 关联 这种是最常用的外部引用样式,第二种讲样式写在 head 头部里面 这种是页面样式 ,第三中样式直接写在行内 style里面 ...
- canvas刮刮卡
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...
- ES禁用_source不会影响聚合
From Elasticsearch's website: The _source field contains the original JSON document body that was pa ...
- BZOJ3165:[HEOI2013]Segment
浅谈标记永久化:https://www.cnblogs.com/AKMer/p/10137227.html 题目传送门:https://www.lydsy.com/JudgeOnline/proble ...
- 选中DataGrid的Cell而不是row
主要是针对DataGridCellsPresenter而不是SelectiveScrollingGrid,使用时DataGridRow应用这个style就可以了. <Style x:Key=&q ...
- Java 日志记录规则
Java 日志记录规则 规则一:日志是面向读者的 我们不应该让无价值的信息使日志文件变得乱糟糟,比如说完整打印所有的实体字段. 通常,实体名字和其逻辑关键字足以识别在表格中的一条记录了. 规则二:匹配 ...
- CF-816A
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...
- R 中数据导入
R语言数据导入 数据导入 1.保存和加载R的数据(与R.data的交互:save()函数和load()函数) a <- 1:10 save(a, file = "data/dumDa ...
- 为什么选择Netty
支持高并发访问 比核心 Java API 更好的吞吐量,较低的延时资源消耗更少,这个得益于共享池和重用减少内存拷贝 https://baike.baidu.com/item/Netty/1006162 ...
- servlet的九大内置对象和四大域对象
隐式对象 说明 request 转译后对应HttpServletRequest/ServletRequest对象 response 转译后对应HttpServletRespons/ServletRes ...