题目http://codeforces.com/contest/1169/problem/C

题意:

有n个数,每次可以选择k个,将他们+1并对m取模。问最少进行多少次操作,使得序列是非递减的。

思路:

太久没刷题遭报应了。这两天能补多少是多少吧。

二分答案。然后看看这个序列是不是非递减的。

对于第i个数,如果$a[i]\leq prev\leq a[i]+mid$,说明在mid次操作内他肯定比他前一个数要大。

当然因为取模 所以实际上还应该包括$a[i]\leq prev+m\leq a[i]+mid$

但如果$prev > a[i]+mid$说明mid不够大,则l = mid +1

否则r = mid

要死了二分都不会了。

 //#include<bits/stdc++>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<stdlib.h>
#include<queue>
#include<map>
#include<stack>
#include<set> #define LL long long
#define ull unsigned long long
#define inf 0x7f7f7f7f using namespace std; int n, m;
const int maxn = 3e5 + ;
int num[maxn]; int main()
{
scanf("%d%d", &n, &m);
for(int i = ; i < n; i++){
scanf("%d", &num[i]);
}
int l = , r = m;
int ans;
while(l < r){
bool flag = false;
int mid = (l + r) / , prev = ;
for(int i = ; i < n; i++){
int x = num[i], y = num[i] + mid;
if(x <= prev && y >= prev || x <= prev + m && y >= prev + m){
continue;
}
if(prev >= x){
flag = true;
break;
}
prev = num[i];
}
if(flag){
l = mid + ;
}
else{
//ans = mid;
r = mid;
}
}
printf("%d\n", l);
return ;
}

codeforces#562 Div2 C---Increasing by modulo【二分】的更多相关文章

  1. codeforces 350 div2 D Magic Powder - 2 二分

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  3. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  4. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  5. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  6. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  7. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  8. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  9. Codeforces Round #562 (Div. 2) C. Increasing by Modulo

    链接:https://codeforces.com/contest/1169/problem/C 题意: Toad Zitz has an array of integers, each intege ...

随机推荐

  1. python3中django-admin找不到core的解决方法

    今天在测试django-admin startproject mysite时,出现以下问题: ImportError: No module named django.core 在执行此命令之前,我将d ...

  2. B7. Concurrent 锁的分类

    [概述] 锁的分类根据不同的维度可以分为以下几种: 悲观锁和乐观锁 共享锁(S锁,读锁)和排他锁(X锁,写锁) 公平锁和非公平锁 重入锁 分段锁 [悲观锁和乐观锁] 悲观锁和乐观锁是两种处理并发冲突的 ...

  3. Redis 常用命令学习一:通用的基本命令

    1-链接,如果需要的 Redis 部署在远程机器上,可以通过以下命令链接,其中-h后面跟着主机名,-p后面跟端口名 redis-cli -h 233.2.2.4 -p 666 2-PING 命令用来测 ...

  4. fontmin字体子集

    怕忘了做个记录 链接:http://ecomfe.github.io/fontmin/#feature 特点:方便,快捷.

  5. MySQL优化 - 性能分析与查询优化(转)

    出处:  MySQL优化 - 性能分析与查询优化 优化应贯穿整个产品开发周期中,比如编写复杂SQL时查看执行计划,安装MySQL服务器时尽量合理配置(见过太多完全使用默认配置安装的情况),根据应用负载 ...

  6. 怎样查看或修改元素节点的id属性

    使用 el.id; el表示获取到的元素节点, 如下所示: // HTML 代码 // <div id="app" class="c1">hello ...

  7. React 工程的 VS Code 插件及配置

    原味地址:https://juejin.im/post/5b5fce12e51d45162679e032 最近使用 VS Code 来开发 React,本文记录一些使用的 VS Code 插件以及离线 ...

  8. go语言中regexp包中的函数和方法

    // regexp.go ------------------------------------------------------------ // 判断在 b 中能否找到正则表达式 patter ...

  9. c++实现单向链表的一些操作

    #include<iostream> #include <algorithm> #include <vector> #include <set> #in ...

  10. Vue介绍:vue导读1

    一.什么是vue 二.如何在页面中使用vue 三.vue的挂载点 四.vue的基础指令 一.什么是vue 1.什么是vue vue.js十一个渐进式javascript框架 渐进式:vue从控制页面中 ...