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 ...
随机推荐
- redis主从同步错误处理
背景: 之前resis只有一台服务器(redis master),现需要为其增加一台slave服务器(slave),做成一主一从 要求,不影响 master的正常情况下完成 . 1.配置slave: ...
- Httpwatch教程
启动Httpwatch 从IE的“查看”—“浏览器栏”—“HttpWatch”启动HttpWatch.如下图所示: 以下是HttpWatch程序界面 以下用登录我的邮箱mail.163.com例子来展 ...
- Redis 原子操作——事务
MULTI 标记一个事务块的开始. 事务块内的多条命令会按照先后顺序被放进一个队列当中,最后由 EXEC 命令原子性(atomic)地执行. 可用版本: >= 1.2.0 时间复杂度: O(1) ...
- 【AtCoder】ARC059
为啥这场ARC那么水--一个点就切完了 ARC059 C - いっしょ / Be Together 枚举就行 #include <bits/stdc++.h> #define fi fir ...
- getContextPath、getServletPath、getRequestURI、getRealPath、getRequestURL、getPathInfo();的区别
<% out.println("getContextPath: "+request.getContextPath()+"<br/>"); ou ...
- Spring与Web框架(例如Spring MVC)漫谈——关于Spring对于多个Web框架的支持
在看Spring MVC的官方文档时,最后一章是关于Spring对于其它Web框架的支持(如JSF,Apache Struts 2.x,Tapestry 5.x),当然Spring自己的MVC框架Sp ...
- 基于bootstrap selectpicker ,实现select下拉框模糊查询功能
1.html代码块 需要引入bootstrap的css js jquery bootstrap.css bootstrap-select.min.css jquery-1.11.3.min.js bo ...
- java方法可变参数研究
1 问题引出 (1)缘由 最近在研究如何在项目中引入Redis缓存,于是遇到可变参数这个疑惑点,之前没有好好研究过,为了避免项目后期出现问题. (2)项目相关技术 SpringBoot Redis K ...
- VMware永久key
VMware永久KEY:5F29M-48312-8ZDF9-A8A5K-2AM0Z
- DDD 理解
DDD提倡充血模型,业务放在类中,而不是服务中,刚开始是比较不清楚的.突然明白,以前开发桌面程序的时候,不就是这样处理了吗?业务分析和代码实现一一对应.因为桌面程序没有数据库,他就是纯粹的面向对象的实 ...