http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=760

撸了个二分查找

 #include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std; int bs(int a[],int n,int len)
{
int lo = ,hi = len-,mid = (lo+hi)/;
while(lo<=hi)
{
if(n<a[mid])
{
hi = mid -;
mid = (lo+hi)/;
}
else if(n>a[mid])
{
lo = mid +;
mid = (lo+hi)/;
}
else
return mid;
}
if(lo>hi)
return -;
} int main()
{
int a[];
int x;
while(cin>>x && x!=-)
{
int i = ;
a[] = x;
while(cin>>a[i])
{
if(a[i]==)
break;
i++;
}
sort(a,a+i);
int count = ;
for(int j = i-;j>=;j--)
{
if(bs(a,a[j]*,i)!=-)
{
count++;
}
}
cout<<count<<endl; }
}

zoj 1760 查找的更多相关文章

  1. zoj 1760 floyd构图+Dinic最大流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 #include <cstdio> #includ ...

  2. zoj 1760 Doubles(set集合容器的应用)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1760 题目描述: As part of an arithmet ...

  3. zoj 1760 Doubles

    Doubles Time Limit: 2 Seconds      Memory Limit: 65536 KB As part of an arithmetic competency progra ...

  4. ZOJ 3156 Taxi (二分匹配+二分查找)

    题目链接:Taxi Taxi Time Limit: 1 Second      Memory Limit: 32768 KB As we all know, it often rains sudde ...

  5. ZOJ 3492 模拟循环链表线性查找

    WA了好几次最后找到错因是因为数组开小了! = = string whose length never exceeds 20 所以至少要开到21 = = ,我却一直开20 ╮(╯▽╰)╭ AC代码: ...

  6. ZOJ 3203 Light Bulb (三分查找)

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  7. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  8. HDU 4430 &amp; ZOJ 3665 Yukari&#39;s Birthday(二分法+枚举)

    主题链接: HDU:pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430 ...

  9. ZOJ 3228 Searching the String(AC自动机)

    Searching the String Time Limit: 7 Seconds      Memory Limit: 129872 KB Little jay really hates to d ...

随机推荐

  1. python学习笔记-练手实例

    1.题目:输出 9*9 乘法口诀表.     程序分析:分行与列考虑,共9行9列,i控制行,j控制列     代码: for i in range(1,10): print ('\r') for j ...

  2. Nginx文件上传下载实现与文件管理

    1.Nginx 上传 Nginx 依赖包下载 # wget http://www.nginx.org/download/nginx-1.2.2.tar.gzinx # wget http://www. ...

  3. iOS中生成随机的UUID

    + (NSString *)uuidString { CFUUIDRef uuid_ref = CFUUIDCreate(NULL); CFStringRef uuid_string_ref= CFU ...

  4. 架构师养成记--17.disrunptor 多生产者多消费者

    入口: import java.nio.ByteBuffer; import java.util.UUID; import java.util.concurrent.CountDownLatch; i ...

  5. 2016级算法第六次上机-G.ModricWang likes geometry

    1116 ModricWang likes geometry 思路 难题,非常考察几何知识,放在这里作为计算几何场次的最难的题. 原题地址 原版题解 代码

  6. Python【每日一问】16

    问: [基础题]TCP/UDP/HTTP协议区别 [提高题]在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数, ...

  7. java四行代码实现图片下载

    如下: InputStream in = new URL("http://www.updown/thumbnail.jpg).openStream(); Path temp = Paths. ...

  8. Mac下使用tree命令

    Mac下没有tree命令,但是可以通过brew进行安装,命令如下: brew install tree 装好后tree的用法和linux下的保持一致.参考:http://www.cnblogs.com ...

  9. jquery的animate关于background-position属性

    jQuery 的 animate 虽然能直接使用 CSS 的方式来进行动画,但有些属性其实是不支持的,例如:background-position. 谷歌支持 background-position- ...

  10. python pip 安装OpenCV

    cmd pip install opencv-contrib-python -i https://pypi.mirrors.ustc.edu.cn/simple/