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后和给 ...
随机推荐
- html5--2.9新的布局元素(5)-hgroup/address
html5--2.9新的布局元素(5)-hgroup/address 学习要点 了解hgroup/address元素的语义和用法 通过实例理解hgroup/address元素的用法 对照新元素布局与d ...
- xgboost算法原理
XGBoost是2014年3月陈天奇博士提出的,是基于CART树的一种boosting算法,XGBoost使用CART树有两点原因:对于分类问题,CART树的叶子结点对应的值是一个实际的分数,而非一个 ...
- VC6.0实用小技巧
VC6.0的若干实用小技巧 .检测程序中的括号是否匹配 把光标移动到需要检测的括号(如大括号{}.方括号[].圆括号()和尖括号<>)前面,键入快捷键 “Ctrl+]”.如果括号匹配正确, ...
- Confd 配置指导
Quick Start Guide Before we begin be sure to download and install confd. Select a backend confd supp ...
- Jenkins远程执行shell出现java: command not found
之前在使用Jenkins执行远程shell脚本时,出现提示java: command not found:多方查找原因后发现是因为远程执行shell脚本时,不会自动加载环境变量,导致出现此错误,解决方 ...
- selectedIndex 属性可设置或返回下拉列表中被选选项的索引号。
转自:https://blog.csdn.net/xxj19950917/article/details/73002046
- CF-845B
B. Luba And The Ticket time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- JVM StackOverflowError vs. OutOfMemoryError
if the computation in a thread needs a larger Java Virtual Machine stack than is permitted, the Java ...
- 【转】eclipse修改workspace
[转]eclipse修改workspace 以下方法选其中一种 1.进入 Window > Preferences > General > Startup and Shutdown ...
- Thinkphp3.2 下载文件的方法
今天做一个功能,刚好遇到了一个要下载文件功能的需求,所以把这个基于thinkphp3.2的文件下载功能,描述一下大概的实现方法. 网上有人说用a链接的方法实现,但是这种方法并不安全.所以我们还是用官方 ...