题目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. python进程池 使用Queue实现计数功能

    多进程中各个进程间相互隔离,进程间通信需要使用到通道. 多进程中使用Queue实现进程中通信 from multiprocessing import Process,Queue import time ...

  2. eXosip的register注册

    转载于:http://blog.sina.com.cn/s/blog_4868f98601018ioh.html 这个测试程序是从eXosip原有的测试程序改造的.原程序是tools 目录下的 sip ...

  3. 【3.4】innodb存储引擎

    [1]Innodb 与 Myisam 的区别 1.InnoDB支持事物,而MyISAM不支持事物 2.InnoDB支持行级锁,而MyISAM支持表级锁 3.InnoDB支持MVCC, 而MyISAM不 ...

  4. cook,session

    //发送session request.getSession().setAttribute("user", "zs1"); //发送cookie //需要自动登 ...

  5. CF1032B Personalized Cup

    一个多月前写的题,既然没人写题解,那蒟蒻就写一篇吧 基本思路 既然是输出任意一个解,那么号的位置在那里是没有关系的.我的思路是默认*号在最后面,然后对输入的字符串输出的行数进行分类. 代码 #incl ...

  6. 【Python基础】09_Python中的元组

    1.元组的定义 Tuple (元组)与列表类似,元组的元素 不能修改 元组通常保存 不同类型 的数据 元组用()定义 info_tuple = ("张三", 18, 1.75) 定 ...

  7. 教你如何进行移动端APP测试

    1.安全测试(权限) 1)软件权限:其中包括发送信息,拨打电话,链接网络,访问手机信息,联系人信息等等 2)数据在本地的存储.传输等 3)执行某些操作时导致的输入有效性验证.授权.数据加密等方面 4) ...

  8. .NET Core 创建Windows服务

    .NET Core 创建Windows服务 作者:高堂 原文地址:https://www.cnblogs.com/gaotang/p/10850564.html 写在前面 使用 TopShelf+Au ...

  9. 让theano在windows下能进行GPU并行的配置步骤

    最近在implement DeepLearning.net上面的程序.对于开源的python,最头疼的就是各种package和各种configuration. 而且还是在windows下. 想要让th ...

  10. 利用django 实现个人博客 全记录(二)

    上一篇文章已经把基础环境搭建好了 一  创建app D:\学习\python3.7.3\python manage.py startapp blog 修改 博客的 models.py ) ) def ...