codeforces-1201 C Maximum Median
二分查找的典型应用,寻找虚无的值代入测试
1 #include <bits/stdc++.h> 2 #define _for(i,a,b) for(int i = (a);i < b;i ++) 3 typedef long long ll; 4 using namespace std; 5 inline ll read() 6 { 7 ll ans = 0; 8 char ch = getchar(), last = ' '; 9 while(!isdigit(ch)) last = ch, ch = getchar(); 10 while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar(); 11 if(last == '-') ans = -ans; 12 return ans; 13 } 14 inline void write(ll x) 15 { 16 if(x < 0) x = -x, putchar('-'); 17 if(x >= 10) write(x / 10); 18 putchar(x % 10 + '0'); 19 } 20 ll n,k; 21 ll a[200006]; 22 bool C(ll d) 23 { 24 ll line = a[n/2]+d; 25 ll tmpk = k; 26 tmpk -= d; 27 _for(i,n/2+1,n) 28 if(a[i]<line) 29 tmpk -= line-a[i]; 30 else 31 break; 32 return tmpk>=0; 33 } 34 ll solve() 35 { 36 ll lb = 0,ub = 1000000002; 37 while(ub - lb > 1) 38 { 39 ll mid = lb+(ub-lb)/2; 40 if(C(mid)) lb = mid; 41 else ub = mid; 42 } 43 return lb; 44 } 45 int main() 46 { 47 n = read(),k = read(); 48 _for(i,0,n) 49 a[i] = read(); 50 sort(a,a+n); 51 ll rnt = solve(); 52 write(rnt+a[n/2]); 53 return 0; 54 }
转载于:https://www.cnblogs.com/Asurudo/p/11301711.html
codeforces-1201 C Maximum Median相关推荐
- 【CodeForces - 1201C】Maximum Median(思维,水题)
题干: You are given an array aa of nn integers, where nn is odd. You can make the following operation ...
- 【CodeForces - 485D】Maximum Value (枚举,用数组离散化,数学,取模运算,因子,筛法)
题干: You are given a sequence a consisting of n integers. Find the maximum possible value of (intege ...
- codeforces 702A A. Maximum Increase(水题)
题目链接: A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input sta ...
- codeforces 332B B. Maximum Absurdity(rmq)
题目链接: codeforces 332B 题目大意: 给出一个序列,让找出不互相覆盖的两个长度为k的段,问在两个段的权值和最大的情况下,按照左边段的左端点排序,右边段的左端点作为第二关键字排序,得到 ...
- Codeforces 1201
C. 解 对数组排序后后缀加.注意中位数的值不一定等于数组中的某个元素. Code #include<bits/stdc++.h> using namespace std; typedef ...
- 【CodeForces - 1060C】Maximum Subrectangle (思维,预处理前缀和,dp,枚举长度)
题干: You are given two arrays aa and bb of positive integers, with length nn and mmrespectively. Let ...
- 【 CodeForces - 1060B 】Maximum Sum of Digits(思维,构造)
题干: You are given a positive integer nn. Let S(x)S(x) be sum of digits in base 10 representation of ...
- 【Codeforces 1157F】 Maximum Balanced Circle | 思维、dp、二分
题目大意: 给出一个序列aia_iai,序列中选出若干个数使它们满足下面条件: 按一定规则排序成为一个环后,任意相邻两项绝对值相差≤1\le 1≤1 输出最多能选择多少个数,并将这些数按照合法的规则 ...
- Codeforces Contest 1144 E Median String —— 水题
This way 题意: 给你两个字符串,问你字典序在这两个字符串正中间的字符串是什么 题解: 好几个星期没做题目了,连1900都想了一段时间,一开始想着用2进制来做,但是想着想着发现直接用2进制做不 ...
最新文章
- python中if语句中可用break_【第四篇】Python的if语句/for..in循环/while循环/break和continue...
- go map并发写错误问题
- 《剑指offer》c++版本 6.从尾到头打印链表
- 【Qt开发】QSplitter的使用和设置
- wepy学习笔记之环境搭建
- 震惊整个世界的新发现,科学界的大骗局
- 我想做个MP3,要怎么入手?
- 无迹卡尔曼滤波器(UKF)
- python处理era5_ERA5数据python批量下载程序
- python3 rsa加密_python3产生RSA秘钥对并执行加解密操作详解
- java入门简单小项目_JAVA入门_java项目接入Mysql8.0
- oss文件普通下载-断点下载
- 转转首席架构师 孙玄:如何成为一个有情怀的工程师?
- 硬件加密芯片介绍 及 加密芯片选择(加密IC) 加密芯片原理
- 由一篇作文《一件有意义的事》展开的
- 基于DSP的主动降噪开发之三(CCS软件学习)
- Aqara绿米董事长游延筠专访:以用户体验为出发点,打造更懂你的家
- 美丽的余霞风景mac高清动态壁纸
- 【肥海豹】-网络安全等级保护(等保)-WINDOWS类服务器配置
- 表格无法无法计算机,电脑表格打不开是怎么回事
热门文章
- mysql从删库到跑路 亚马逊_Amazon RDS 上的 MySQL 的已知问题和限制 - Amazon Relational Database Service...
- 次世代游戏设计的相关介绍
- 收藏 | 损失函数实现数据扩增
- C++ Primer 第五版 第8章类 8.2——文件输入和输出
- mysql主从不同步不报错_MySQL主从不同步解决
- mysql有闪回吗_mysql 闪回测试
- Python 按坐标进行文字剪裁
- paddleocr常见问题(3)
- 这就是数据分析之数据集成
- 图像分割总体介绍——深度AI科普团队