题目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. upw,c#,代码实现关闭,重启应用

    微软为uwp直接提供了这些API,可以很容易的直接进行调用 关闭 using Windows.ApplicationModel.Core; CoreApplication.Exit(); or usi ...

  2. 《PC Assembly Language》读书笔记

    本书下载地址:pcasm-book. 前言 8086处理器只支持实模式(real mode),不能满足安全.多任务等需求. Q:为什么实模式不安全.不支持多任务?为什么虚模式能解决这些问题? A: 以 ...

  3. oracle杀死正在执行的进程

    1 查询目前正在执行的终端和进程, SELECT /*+ rule */ s.username,decode(l.type,'TM','TABLE LOCK','TX','ROW LOCK',NULL ...

  4. JDBC 资源绑定器 ,处理查询结果集

    使用资源绑定器绑定属性配置 实际开发中不建议把连接数据库的信息写死到Java程序中 //使用资源绑定器绑定属性配置 ResourceBundle bundle = ResourceBundle.get ...

  5. css走马灯,一步一停(专家介绍类型)

    <div class="CON--cen-pd3 clear aniview slow" data-av-animation="fadeIn"> & ...

  6. 【Python基础】13_Python中的PASS

    pass关键字的使用 在程序分支中,如果不想立刻执行该分支,可使用pass占位符,pass不表示任何含义,仅保证程序不会报错. 如: action_str = input("请选择希望执行的 ...

  7. django 中静态文件项目加载问题

    问题描述: django项目中创建了多个app后,每个app中都有对应的static静态文件.整个项目运行时这些静态文件的加载就是一个问题,因为整个项目我只参与了一部分,项目部署之类的并没有参与.我写 ...

  8. MySQL反应慢排查思路

    数据库异常假死排查需要数据(当时问题的时间,前后时间在2个小时的数据就行) 1.MySQL相关配置 整体可以借助于pt-mysql-summary生成(percona-tools工具) 2.操作系统方 ...

  9. 转载博客(Django2.0集成xadmin管理后台遇到的错误)

    转载博客地址:https://blog.csdn.net/yuezhuo_752/article/details/87916995 django默认是有一个admin的后台管理模块,但是丑,功能也不齐 ...

  10. ES6模块化及优点,简单案例让你秒懂

    模块化:模块是一个文件     好处:         1.减少命名冲突         2.避免引入时的层层依赖         3.可以提升执行效率     **第一种方法************ ...