用到二分搜索的抽签问题
2016-04-08 19:13
218 查看
poj上的搜索题一会再做,先做一道简单的~~
#include <iostream> #include<algorithm> using namespace std; int k[100]; int kk[100]; int n; bool f; bool binary_search(int x) { int l = 0, r = n; int mid; while(l < r) { mid = (l+r)/2; if(kk[mid] == x) return true; else if(x < kk[mid]) r = mid - 1; else l = mid + 1; } return false; } int main() { int m; cin >> n >> m; for(int i=0; i<n; i++) { cin >> k[i]; } int a, b, c, d; for(int c=0; c<n; c++) { for(int d=0; d<n; d++) { kk[c*n + d] = k[c] + k[d]; } } sort(kk,kk+n*n); for(a=0; a<n; a++) { for(b=0; b<n; b++) { if(binary_search(m-k[a]-k[b])) f = true; } } if(f) cout << "Yes\n"; else cout << "No\n"; return 0; }
相关文章推荐
- Bless all.
- 加密解密技术基础、PKI及创建私有CA
- 【NOIP模拟】有趣的有趣的家庭菜园
- 下拉框多选
- PID-4769-Animals
- 记一次未解决的异常:java.lang.NoClassDefFoundError: net/sf/json/JSONObject
- 计算数学表达式
- 111
- 修改Python IDLE代码配色及语法高亮主题
- centos6.5环境通达OA数据库mysql5.0.67升级至mysql5.5.48方案
- 1002:归并排序
- 安卓平台架构及特性
- centos6.5环境通达OA数据库mysql5.0.67升级至mysql5.5.48方案
- [Java8 Collection源码+算法+数据结构]-List(二)
- 阐述线程状态之间的关系
- Eclipse的PHP插件PHPEclipse安装和使用
- 线性表 及Java实现 顺序表、链表、栈、队列
- 浅谈套接字编程—TCP
- Android Bluetooth 框架简读 <3>
- (Vagrant Vs Docker)Should I use Vagrant or Docker for creating an isolated environment?