首页 > 其他 > 详细

2.7.3

时间:2016-12-30 02:37:23      阅读:191      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include"array.h"
using namespace std;
#define SUCCESS 1
#define FAIL 0
static int result = 0;

int find(int *a , int p , int q , int r , int x)
{
	int n1 = q - p + 1;
	int n2 = r - q;
	int *b = (int *)malloc(sizeof(int)*n1);
	copyArray(a , b , p , q);
	int *c = (int *)malloc(sizeof(int)*n2);
	copyArray(a , c , q + 1 , r);
	for(int i = 0 ; i < n1 ; i++ )
	{
		if(indexOf(c ,n2 , x - b[i]) != -1)
			return SUCCESS;
	}
	return FAIL;
}

int findDivition(int *a , int p , int q , int x)
{
	if(p < q)
	{
		int r = (p + q)>>1;
		findDivition(a , p , r , x);
		findDivition(a , r + 1 , q , x);
		return result += find(a , p , r , q , x);
	}
}

int main()
{
	int a[10] = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10};
	cout<<findDivition(a , 0 , 9 , 20);
	system("pause");
}

  

2.7.3

原文:http://www.cnblogs.com/GaryWant/p/6235395.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!