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后和给 ...
随机推荐
- 微信video和audio无法自动播放解决方案
//音频,写法一<audio src="music/bg.mp3" autoplay loop controls>你的浏览器还不支持哦</audio> // ...
- selenium中类名不能与方法名相同
不要将selenium中的类名命名成需要用到的方法名,不然会报错!
- (转)Linux内核本身和进程的区别 内核线程、用户进程、用户线程
转自:http://blog.csdn.net/adudurant/article/details/23135661 这个概念是很多人都混淆的了,我也是,刚开始无法理解OS时,把Linux内核也当做一 ...
- linux C++ scandir 的使用
() 头文件 #include <dirent.h> () 函数定义 int scandir(const char *dir,struct dirent **namelist,int (* ...
- arm-linux-gcc4.4.3编译busybox-1.25.0
系统环境: 1.操作系统:Ubuntu16.04 2.交叉编译工具链:arm-linux-gcc4.4.3 3.busybox源码包:busybox-1.25.0 一.修改Makefile配置 首先解 ...
- vue之axios+php+mysql
博主原创,未经许可请勿转载 哦 1.axios配置请看上篇 2.mysql数据库编写,表名为area_list 3.json.php文件在notebeans中编写 <?php header('C ...
- JVM(一)虚拟机内存划分
Java内存区域 线程私有数据区域:虚拟机栈,本地方法栈,程序计数器 线程共享数据区域:方法区,堆 程序计数器:当前线程所执行的字节码的行号指示器,JVM通过这个字节码解释器改变计数器的值,以选择下一 ...
- C++之MutexLock和MutexLockGuard封装
noncopyable.h #ifndef __WD_NONCOPYABLE_H__ #define __WD_NONCOPYABLE_H__ namespace wd { class Noncopy ...
- [RTOS]--uCOS、FreeRTOS、RTThread、RTX等RTOS的对比之特点
本篇博客就来细数这几个RTOS的特点. 以下内容均来自官方网站或者官方手册Feature的Google翻译的加了我的一些调整,没有任何主观成分. 1. FreeRTOS FreeRTOS是专为 ...
- Mysql常用命令行大全(二)
#登录数据库mysql -hlocalhost -uroot -p;#修改密码mysqladmin -uroot -pold password new; #显示数据库show databases;#显 ...