Educational Codeforces Round 64 -C(二分)
题目链接:https://codeforces.com/contest/1156/problem/C
题意:给出n个数和整形数z,定义一对数为差>=z的数,且每个数最多和一个数组成对,求最多有多少对。
思路:先按升序排序,在区间[0,n/2]二分答案即可,判断m是否满足条件利用贪心思想,即看前x个数和后x个数是否能对应组成对。
AC代码:
#include<cstdio>
#include<algorithm>
using namespace std; int n,z,a[]; bool judge(int x){
bool ans=true;
for(int i=;i<x;++i)
if(a[i]+z>a[n+i-x]){
ans=false;
break;
}
return ans;
} int main(){
scanf("%d%d",&n,&z);
for(int i=;i<n;++i)
scanf("%d",&a[i]);
sort(a,a+n);
int l=,r=n/,m;
while(l<=r){
m=(l+r)>>;
if(judge(m)) l=m+;
else r=m-;
}
printf("%d\n",r);
return ;
}
Educational Codeforces Round 64 -C(二分)的更多相关文章
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
- Educational Codeforces Round 64 部分题解
Educational Codeforces Round 64 部分题解 不更了不更了 CF1156D 0-1-Tree 有一棵树,边权都是0或1.定义点对\(x,y(x\neq y)\)合法当且仅当 ...
- Educational Codeforces Round 64(ECR64)
Educational Codeforces Round 64 CodeForces 1156A 题意:1代表圆,2代表正三角形,3代表正方形.给一个只含1,2,3的数列a,ai+1内接在ai内,求总 ...
- Educational Codeforces Round 64部分题解
Educational Codeforces Round 64部分题解 A 题目大意:给定三角形(高等于低的等腰),正方形,圆,在满足其高,边长,半径最大(保证在上一个图形的内部)的前提下. 判断交点 ...
- Educational Codeforces Round 64 (Rated for Div. 2) (线段树二分)
题目:http://codeforces.com/contest/1156/problem/E 题意:给你1-n n个数,然后求有多少个区间[l,r] 满足 a[l]+a[r]=max([l, ...
- Educational Codeforces Round 64 C. Match Points 【二分思想】
一 题面 C. Match Points 二 分析 根据题意很容易想到要去找满足条件的数,因为可以打乱输入的顺序,所以很容易想到二分. 但是如果直接对输入的数组进行二分,如输入$a$,直接在数组里二分 ...
- Educational Codeforces Round 61 D 二分 + 线段树
https://codeforces.com/contest/1132/problem/D 二分 + 线段树(弃用结构体型线段树) 题意 有n台电脑,只有一个充电器,每台电脑一开始有a[i]电量,每秒 ...
- Educational Codeforces Round 64 (Rated for Div. 2) A,B,C,D,E,F
比赛链接: https://codeforces.com/contest/1156 A. Inscribed Figures 题意: 给出$n(2\leq n\leq 100)$个数,只含有1,2,3 ...
- Educational Codeforces Round 15 C 二分
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 自定义 Swiper 的pageControl
.part5-bg .swiper2 .swiper-pagination2{ bottom: 0.4rem; } /*未选中的小圆点样式*/ .part5-bg .swiper2 .swiper-p ...
- LAMP 搭建,wordpress.xcache,powerdns及poweradmin
一,概念 CGI: CGI全称是通用网关接口(Common Gateway Interface),是外部应用程序与与服务器之间的接口标准,是在CGI程序和web服务器之间传递信息的规程 CGI是一段程 ...
- js中的“==”与“===”的区别
console(34 == "34") 输出true console(34 === "34") 输出false 因此,== 只判断值,不判断类型,实际上里 ...
- php上传大文件1G
前段时间做视频上传业务,通过网页上传视频到服务器. 视频大小 小则几十M,大则 1G+,以一般的HTTP请求发送数据的方式的话,会遇到的问题:1,文件过大,超出服务端的请求大小限制:2,请求时间过长, ...
- sh_05_列表遍历
sh_05_列表遍历 name_list = ["张三", "李四", "王五", "王小二"] # 使用迭代遍历列表 ...
- ant design 的表格默认选中
在使用 ant design 的表格时候使用默认选中项, 需要配置的 Table 的 rowSelection const rowSelection = { type: 'checkbox', get ...
- Android 造炫目的圆形菜单 秒秒钟高仿建行圆形菜单
1.概述 今天打开建行看存款,一看伤心欲绝,再看:我擦,这个圆形菜单挺炫.于是,为了掩盖我悲痛的心情,我决定是实现这个效果.好了,其实还有个原因,记得我初学android那会我做的应用被鄙视了,说我的 ...
- 关于多个py文件生成一个可运行exe文件(用pyinstaller)
首先下载Pyinstaller,在cmd命令下执行:pip installer Pyinstaller,不需要关心安装在哪 然后把所有相关的py文件都放在一个目录下 在那个目录下执行cmd命令:pyi ...
- DVWA--File Inclusion(不能远程包含的问题解决)
然后别以为这样就完了 我被这样坑了一下午 找到你对应版本的php 进去Ctrl+f 搜索url_allow——fopen 和include
- C++入门经典-例5.3例5.4-输出int指针运算后的地址值
1:代码如下: // 5.3.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...