Java教程

二维数组

本文主要是介绍二维数组,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package main

import (
	"fmt"
	"math"
	"sync"
	"time"
)

var maxInt64Float float64
var maxNum int64
var resultChan chan bool
var wg sync.WaitGroup

func main() {
	startTime := time.Now()
	defer func() {
		cost := time.Since(startTime)
		fmt.Println("Run Time=", cost)
	}()
	resultChan = make(chan bool, 1)
	var numResult []int64
	numResult = append(numResult, 0)
	maxInt64Float = float64(math.MaxInt64)
	maxNum = int64(math.Pow(maxInt64Float, float64(1)/3))
	var i int64
	for i = 1; i <= maxNum; i++ {
		numResult = append(numResult, i*i*i)
	}

	size := maxNum / 10
	wg.Add(10)
	for start := int64(0); start < maxNum; start += size {
		end := start + size
		if end > maxNum {
			end = maxNum
		}
		if start < 3 {
			start = 3
		}
		go fermat(numResult, start, end)

	}
	wg.Wait()

}
func fermat(numResult []int64, start, end int64) {

	var n int64
	//升序排列前两个最小数没有可能 等于另外2个数相加和
	for n = start; n < end; n++ {
		fmt.Println("n=", n, "numResult[n]=", numResult[n])
		var i, j int64
		i = 1
		j = n - 1
		for i < j {
			if numResult[i]+numResult[j] == numResult[n] {
				resultChan <- true
				return
			}
			if numResult[i]+numResult[j] > numResult[n] {
				j--
			}
			if numResult[i]+numResult[j] < numResult[n] {
				i++
			}
		}
	}
	wg.Done()

}

  

这篇关于二维数组的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!