①使用binary_search前要先保证有序

②binary_search函数仅返回true或false

③binary_search(first element, laste lment + 1, data to search)

 #include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
struct PLANT{
int x, y;
};
PLANT map[];
int r, c, num;
int max_num; bool operator < (const PLANT & p1, const PLANT & p2){
if(p1.x == p2.x) return p1.y < p2.y;
return p1.x < p2.x;
} int function(int dx, int dy, int x, int y){
int flag = ;
while(x >= && x <= r && y >= && y <= c){
PLANT temp;
temp.x = x;
temp.y = y;
if(!binary_search(map, map+num, temp)) return ;
x += dx;
y += dy;
++flag;
}
return flag;
}
int main(){
int i, j, k, t;
int num_x, num_y;
int flag;
scanf("%d%d",&r,&c);
scanf("%d",&num);
for(i = ; i < num; ++i) scanf("%d%d",&map[i].x,&map[i].y); sort(map, map+num);
max_num = ; for(i = ; i < num; ++i){
for(j = i + ; j < num; ++j){
int dx = map[j].x - map[i].x;
int dy = map[j].y - map[i].y;
int px = map[i].x - dx;
int py = map[i].y - dy;
if(px >= && px <= r && py >= && py <= c) continue; if(map[i].x + max_num * dx > r) continue;
int pY = map[i].y + max_num * dy;
if(pY > c || pY < ) continue; px = dx + map[j].x;
py = dy + map[j].y;
int flag = ;
while(px >= && px <= r && py >= && py <= c){
PLANT temp;
temp.x = px;
temp.y = py;
if(!binary_search(map, map+num, temp)){
flag = ;
break;
}
px += dx;
py += dy;
++flag;
}
max_num = max(max_num, flag);
}
}
if(max_num == ) printf("0\n");
else printf("%d\n",max_num);
return ;
}

POJ1054 枚举【STL__binary_search()_的应用】的更多相关文章

  1. 零基础逆向工程40_Win32_14_枚举窗口_模拟鼠标键盘

    1 查找窗口 1.1 代码案例 //查找指定窗口 TCHAR szTitle[MAX_PATH] = {0}; HWND hwnd = ::FindWindow(TEXT("#32770&q ...

  2. 【t081】序列长度(贪心做法)

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 有一个整数序列,我们不知道她的长度是多少(即序列中整数的个数),但我们知道在某些区间中至少有多少个整数 ...

  3. [loj2586]选圆圈

    下面先给出比较简单的KD树的做法-- 根据圆心建一棵KD树,然后模拟题目的过程,考虑搜索一个圆 剪枝:如果当前圆[与包含该子树内所有圆的最小矩形]都不相交就退出 然而这样的理论复杂度是$o(n^2)$ ...

  4. BZOJ_1406_[AHOI2007]密码箱_枚举+数学

    BZOJ_1406_[AHOI2007]密码箱_枚举+数学 Description 在一次偶然的情况下,小可可得到了一个密码箱,听说里面藏着一份古代流传下来的藏宝图,只要能破解密码就能打开箱子,而箱子 ...

  5. .Net基础篇_学习笔记_第八天_复杂数据类型(常量/枚举/结构)

    1.常量: 声明的常量的语法:const 变量类型 变量名=值;最大的特点就是,声明了常量后,就不能再被重新赋值. 2.枚举 语法:[public] enum 枚举名{ 值1, 值2, 值3, ... ...

  6. C#(结构体_枚举类型)

        结构体一般定义在Main函数上面,位于Class下面,作为一个类:一般情况Struct定义在Main函数前面,Main函数里面的地方都可以使用,参数前面加上public代表公用变量. 用法 1 ...

  7. C#_枚举类型

     C#中的枚举是名/值对的数据类型,下面是自定义的军衔等级的枚举 //定义枚举 enum MilitaryRank { Commander, ArmyCorpCommander, Military ...

  8. c#中[Flags] 枚举类型定义问题_百度知道

    [Flags]的微软解释是“指示可以将枚举作为位域(即一组标志)处理.”其实就是在编写枚举类型时,上面附上Flags特性后,用该枚举变量是既可以象整数一样进行按位的“|”或者按位的“&”操作了 ...

  9. C# 语言规范_版本5.0 (第14章 枚举)

    1. 枚举 枚举类型 (enum type) 是一种独特的值类型(第 4.1 节),它用于声明一组命名的常量. 下面的示例 enum Color { Red, Green, Blue } 声明一个名为 ...

随机推荐

  1. POJ 1151Atlantis 扫描线+线段树求矩形面积并

    题目链接 #include <iostream> #include <vector> #include <cstdio> #include <cstring& ...

  2. java 类排序

    参考文档:Java排序: Comparator vs Comparable 入门 java类经常面临排序问题,据我所知:java提供comparable和comparator两种比较方式: 1. co ...

  3. Cyclomatic complexity

    Cyclomatic Code Complexity was first introduced by Thomas McCabe in 1976. In 1976, Thomas McCabe pub ...

  4. 让程序只运行一个实例(Delphi篇)(三种方法,其中使用全局原子的方法比较有意思)

    Windows 下一个典型的特征就是多任务,我们可以同时打开多个窗口进行操作,也可以同时运行程序的多个实例,比如可以打开许多个资源管理器进行文件的移动复制操作.但有时出于某种考虑(比如安全性),我们要 ...

  5. perl5 第十二章 Perl5中的引用/指针

    第十二章 Perl5中的引用/指针 by flamephoenix 一.引用简介二.使用引用三.使用反斜线(\)操作符四.引用和数组五.多维数组六.子程序的引用  子程序模板七.数组与子程序八.文件句 ...

  6. 特殊集合(stack、queue、hashtable的示例及练习)

    特殊集合:stack,queue,hashtable stack:先进后出,一个一个的赋值一个一个的取值,按照顺序. .count           取集合内元素的个数 .push()        ...

  7. innerhtml和innertext的用法以及区别

    例如: <div id="test"> <span style="color:red">test1</span> test2 ...

  8. linux账户管理(centos)

    1./etc/passwd 非常详细的/etc/passwd解释 http://luzl.iteye.com/blog/564404 vi /etc/passwd,可以看到如下信息,在最后一行可以看到 ...

  9. 条款21: 必须返回对象时,不要强行返回对象的reference

    总结: 绝不要返回一个local栈对象的指针或引用:绝不要返回一个被分配的堆对象的引用:绝不要返回一个静态局部对象(为了它,有可能同时需要多个这样的对象的指针或引用). 条款4中给出了“在单线程环境中 ...

  10. poj 3335 /poj 3130/ poj 1474 半平面交 判断核是否存在 / poj1279 半平面交 求核的面积

    /*************** poj 3335 点序顺时针 ***************/ #include <iostream> #include <cmath> #i ...