zoj 1101 二分搜索
来源:互联网 发布:阿里云短信怎么使用 编辑:程序博客网 时间:2024/06/05 11:11
/**
感觉时间复杂度还是太高了,一开始自己写了个二分搜索。比STL里的要慢个几毫秒。可能是数据量太少了,体现不出来。
*/
#if 1#include <iostream>#include <cstdio>#include <string.h>#include <algorithm>using namespace std;#define MY_MAX 1001long dight[MY_MAX]={0};int cmp(const void *a ,const void *b){return *(long *)a - *(long *)b;}void solve(int n ){qsort(dight,n,sizeof(long),cmp);for(int i = n -1; i >= 0 ;i-- ){for(int j = 0 ; j < n;j++){long X = dight[ i ] - dight[j];for(int k = 0 ; k < n;k++){if (i == j || j == k || i == k) continue; long x2 = X - dight[k];if(x2 != dight[j] && x2!= dight[i]&& x2 != dight[k]&&binary_search(dight, dight + n, x2) ) {printf("%ld\n",dight[i]); return ;}}}}printf("no solution\n");return ;}int main(){int n;long a,result;while(scanf("%d",&n),n){for(int i = 0 ;i < n;i++)scanf("%ld",&dight[i]); solve(n);}return 0;}#endif
- zoj 1101 二分搜索
- ZOJ 1002 Fire Net (搜索 || 二分图)
- zoj 2868 Incredible Cows 二分状态搜索
- ZOJ 1101 Gamblers 二分
- zoj 1101 搜索
- ZOJ 1101 Gamblers (简单搜索)
- zoj 1101Gamblers排序,搜索
- zoj 1101 Gamblers(快排+二分)
- ZOJ--1101:Gamblers(二分查找)
- 二分搜索
- 二分搜索
- 二分搜索
- 二分搜索
- 二分搜索
- 二分搜索
- 二分搜索
- 二分搜索
- 二分搜索
- SQL server--视图(view)
- 验收房子时的N个小窍门 手把手教你买房子
- const在C和C++中的区别
- 0724
- 让nginx的proxy_store和proxy_cache支持ctrl+f5和PURGE二种方
- zoj 1101 二分搜索
- HTTP代理模块(HTTP Proxy)
- 试读《神一样的产品经理》
- hdu 1021
- js获取file文件对象大小
- JPEG驱动
- 用java把MS office(ppt、excel、word、txt) 转换成 flash,并进行播放(linux、windows)
- 新房子的装修步骤
- struts2常用标签的使用