686MS

 #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm> using namespace std; int a[]; int n; bool bsearch(int key)
{
int lo = ,hi = n-,mid = lo+(hi-lo)/;
while(lo<=hi)
{
if(key==a[mid])
return true;
else if(key >a[mid])
{
lo = mid+;
mid = lo+(hi-lo)/; }
else
{
hi = mid-;
mid =lo+(hi-lo)/;
}
}
return false;
} int main()
{
int t,m,i;
scanf("%d",&t);
while (t--)
{
scanf("%d%d",&n,&m);
for(i = ;i<n;i++)
scanf("%d",&a[i]);
int count = ; sort(a,a+n); for(i = ;i<n;i++)
{
if(a[i]>m/) break; if(a[i] == a[i-])
continue; if(*a[i]==m)
count++;
else if(bsearch(m-a[i]))
count+=;
}
printf("%d\n",count);
}
return ;
}

HDU 2578(二分查找)的更多相关文章

  1. Equations(hdu 1496 二分查找+各种剪枝)

    Equations Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. Pie(hdu 1969 二分查找)

    Pie Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  3. Can you find it?(hdu 2141 二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  4. hdu 2141:Can you find it?(数据结构,二分查找)

    Can you find it? Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/10000 K (Java/Others ...

  5. hdu 2141 Can you find it?(二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2141 题目大意:查找是否又满足条件的x值. 这里简单介绍一个小算法,二分查找. /* x^2+6*x- ...

  6. HDU 4614 线段树+二分查找

    Vases and Flowers 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4614 Problem Description Alice is s ...

  7. hdu 2141 Can you find it?(二分查找变例)

    Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...

  8. Can you find it? HDU - 2141 (二分查找)

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

  9. HDU 5288 OO&#39;s sequence (2015多校第一场 二分查找)

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  10. HDU 2141 Can you find it?【二分查找是否存在ai+bj+ck=x】

    Give you three sequences of numbers A, B, C, then we give you a number X. Now you need to calculate ...

随机推荐

  1. robot framework学习笔记之一 资源文件(Resource)和外部资源(External Resources)

    一.资源文件(Resource) 测试套件主要是存放测试案例,资源文件主要是用来存放用户关键字. 添加资源    在目录型的Project/Test Suite下单击鼠标右键,选择『New Resou ...

  2. [实战] SSH 图形化转发

    [实战] SSH 图形化转发 一.介绍 Unix Like操作系统不是只能进行服务器的架设而已,在美编.排版.制图.多媒体应用上也是有其需要的.这些需求都需要用到图形介面(Graphical User ...

  3. date命令的基本用法

    date设置时间 设置时间:-s参数 date -s "20190426 15:22:33" date查看时间差  (-d参数多用于脚本) 查看时间差:-d参数date -d &q ...

  4. Linux基础篇–shell脚本编程基础

    本章内容概要  编程基础  脚本基本格式  变量  运算  条件测试  配置用户环境 7.1 编程基础程序:指令+数据程序编程风格:   过程式:以指令为中心,数据服务于指令   对象式:以数据为中心 ...

  5. java的MethodHandle类详解

    一.总述   java7为间接调用方法提供了MethodHandle类,即方法句柄.可以将其看作是反射的另一种方式. 这是使用MethodHandle调用方法的一个例子: public class T ...

  6. django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty

    https://www.e-learn.cn/content/wangluowenzhang/165461 问题: I created a new project in django and past ...

  7. Mac拷贝/复制文件夹路径快捷键

    快捷键:Option+Command+C 显示路径在Finder: defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES ...

  8. C# 文件读写系列二

    读取文件原则上非常简单,但它不是通过FileInfo和DirectoryInfo来完成的,关于FileInfo和DirectoryInfo请参考C# 文件操作系列一,在.Net Framework4. ...

  9. JAVA的NIO的新特性和小Demo,进一步了解NIO

    1.为什么要用NIO NIO 的创建目的是为了让 Java 程序员可以实现高速 I/O 而无需编写自定义的本机代码.NIO 将最耗时的 I/O 操作(即填充和提取缓冲区)转移回操作系统,因而可以极大地 ...

  10. solr实时更新mysql数据的方法

    第一步:创建core core是solr的特有概念,每个core是一个查询数据,.索引等的集合体,你可以把它想象成一个独立数据库,我们创建一个新core:名字[core1] 进入linux命令行,进入 ...