POJ PKU 2549 二分
(2010-04-29 16:00:32)
标签:
pojpku2549it |
分类: 杂题 |
题目描述:
给你一个集合,让你从中找出4个不同的数字a, b, c, d。满足a b c = d。
找出最大的d。
解题报告:
首先把任意两两组合可能的和存到数组y中,y需要n^2的大小。
把y排序后,然后再枚举任意两两组合d,c,二分搜索d - c是不是在y中,并判断合理性即可。
时间复杂度:
n^2 log(n^2)
代码如下:
#include<iostream>#include<vector>
#include<algorithm>
using namespace std;
int n, x[1000], cnt;
struct q{int num, a, b;}y[1000000];
bool cmp(q a, q b){return a.num < b.num;}
bool search(int d, int c)
{
}
int main()
{