codeforces#562 Div2 C---Increasing by modulo【二分】
题目: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【二分】的更多相关文章
- 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 ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- 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.3.4 Fork/Join框架
package com.study.forkjoin; import java.util.ArrayList; import java.util.List; import java.util.conc ...
- Photon Server 实现注册与登录(三) --- 前端UI设计和发起请求
一.打开之前的测试项目.先将服务端代码编译一下,在 bin/Debug/目录下会发现有一个Common.dill.我们相应导入到前端使用.直接拖拽到相应地方 UI相应布局属于前端操作,这里就不做介绍了 ...
- Python 【Debug排除程序故障】
debug #排除程序故障 print()函数常和#号注释结合在一起用来debug 多行注释有两种快捷操作:1.在需要注释的多行代码块前后加一组三引号''' 2.选中代码后使用快捷键操作:Window ...
- S02_CH03_EMIO实验Enter a post title
S02_CH03_EMIO实验 3.1 EMIO 和MIO的对比介绍 上次讲到MIO的使用,初步熟悉了EDK的使用,这次就来说说EMIO的使用.如你所见zynq的GPIO,分为两种,MIO(multi ...
- UI自动化的第一步(Python,pip,selenium,PyCharm安装配置)
一,py安装 1.python下载,安装,环境配置 地址:https://www.runoob.com/python/python-install.html 注意:安装时,要勾选自动配置环境变量.这样 ...
- Promise.all的使用
我有一个需求如下: 有一个学生号的数组,根据这个数组,取出相关学生的所有信息.获取学生信息的接口用setTime模拟,假设每次请求需要耗时2s,代码如下 // 获取学生信息接口 function ge ...
- TypeScript入门四:TypeScript的类(class)
TypeScript类的基本使用(修饰符) TypeScript类的抽象类(abstract) TypeScript类的高级技巧 一.TypeScript类的基本使用(修饰符) TypeScript的 ...
- redis—django-redis
自定义连接池 这种方式跟普通py文件操作redis一样,代码如下: views.py import redis from django.shortcuts import render,HttpResp ...
- 关于linux一些备份、还原,压缩,归档的命令
15.1 gzipgzip(1) 是GNU的压缩程序.它只对单个文件进行压缩.基本用法如下:$ gzip filename程序执行以后,文件名会变成filename.gz,而且一般情况下大小会比原文件 ...
- PAT Advanced 1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the p ...