• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ProblemReader.ProblemReader类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中codejam/ProblemReader.ProblemReader的典型用法代码示例。如果您正苦于以下问题:Golang ProblemReader类的具体用法?Golang ProblemReader怎么用?Golang ProblemReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ProblemReader类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: solver

func solver(in *ProblemReader.ProblemReader) string {
	turnAround := in.Num()
	nums := in.NNums(2)
	nA, nB := nums[0], nums[1]
	allTrips := make([]trip, nA+nB)

	for _, v := range allStations {
		v.clear()
	}

	for j := 0; j < nA; j++ {
		allTrips[j] = readTrip(in, A, B)
	}
	for j := 0; j < nB; j++ {
		allTrips[nA+j] = readTrip(in, B, A)
	}
	sort.Sort(tripArray(allTrips))

	for _, t := range allTrips {
		src, dst := allStations[t.src], allStations[t.dst]

		// fmt.Printf("trip:%v, from %v to %v\n", t, src, dst)

		src.getTrain(t.depart)
		dst.addTrain(t.arrive + turnAround)
	}

	return fmt.Sprintf("%d %d", allStations[A].reserved, allStations[B].reserved)
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:29,代码来源:TrainTimetable.go


示例2: solver

func solver(in *ProblemReader.ProblemReader) string {
	word := []byte(in.Line())
	lastVal = -1

	letterVal := make(map[byte]int)
	for _, c := range word {
		if _, ok := letterVal[c]; !ok {
			letterVal[c] = nextVal()
		}
	}

	base := int64(lastVal + 1)
	if base == 1 {
		base++
	}
	sum := int64(0)
	mul := int64(1)

	//fmt.Println("letterVal: ", letterVal, "word:", word)

	for j := len(word) - 1; j >= 0; j-- {
		sum += mul * int64(letterVal[word[j]])
		//fmt.Println("letter: ", word[j], "val: ", letterVal[word[j]], "mul: ", mul, "sum: ", sum)
		mul *= base
	}
	return fmt.Sprintf("%d", sum)
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:27,代码来源:AllYourBase.go


示例3: solver

func solver(in *ProblemReader.ProblemReader) string {
	words := in.Words()

	reversed := make([]string, len(words))
	for pos, word := range words {
		reversed[len(words)-pos-1] = word
	}
	return strings.Join(reversed, " ")
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:9,代码来源:ReverseWords.go


示例4: loadBoard

func loadBoard(in *ProblemReader.ProblemReader) *board {
	hw := in.NNums(2)
	b := new(board)
	b.height, b.width = hw[0], hw[1]
	b.cell = make([][]*Cell, b.height)
	for j := 0; j < b.height; j++ {
		b.cell[j] = make([]*Cell, b.width)
		altitude := in.NNums(b.width)
		for k := 0; k < b.width; k++ {
			b.cell[j][k] = &Cell{altitude: altitude[k]}
		}
	}
	return b
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:14,代码来源:Watersheds.go


示例5: solver

func solver(in *ProblemReader.ProblemReader) string {
	n := in.Num()
	v1 := in.NNums(n)
	v2 := in.NNums(n)

	sort.SortInts(v1)
	sort.SortInts(v2)

	var sum int64 = 0

	for j := 0; j < n; j++ {
		sum += int64(v1[j]) * int64(v2[n-j-1])
	}
	return fmt.Sprint(sum)
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:15,代码来源:MinimumScalarProduct.go


示例6: solver

func solver(in *ProblemReader.ProblemReader) string {
	nums := in.NNums(2)
	board, toWin := nums[0], nums[1]
	assert(toWin <= board)
	lines := make([]string, board)
	for j := 0; j < board; j++ {
		line := []byte(in.Line())
		if len(line) != board {
			log.Fatalf("Expected %#v to be %d long", string(line), board)
		}
		shiftLine(line)
		lines[j] = string(line)
	}
	return winner(lines, toWin)
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:15,代码来源:Rotate.go


示例7: solver

func solver(in *ProblemReader.ProblemReader) string {
	line := in.Line()
	scores := make([]int, len(PATTERN))
	for j := range line {
		c := line[j]
		for k := len(PATTERN) - 1; k >= 0; k-- {
			if c == PATTERN[k] {
				if k == 0 {
					scores[k] = (scores[k] + 1) % 10000
				} else {
					scores[k] = (scores[k] + scores[k-1]) % 10000
				}
			}
		}
	}
	return fmt.Sprintf("%04d", scores[len(scores)-1])
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:17,代码来源:WelcomeToCodeJam.go


示例8: solver

func solver(in *ProblemReader.ProblemReader) string {
	n := in.Num()
	wires := make([]Wire, n)

	for j := 0; j < n; j++ {
		wire := in.NNums(2)
		wires[j] = Wire{wire[0], wire[1]}
	}
	sort.Sort(WireSlice(wires))

	cross := 0
	for j := 0; j < n; j++ {
		for k := j + 1; k < n; k++ {
			if wires[k].b < wires[j].b {
				cross++
			}
		}
	}
	return fmt.Sprintf("%d", cross)
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:20,代码来源:RopeIntranet.go


示例9: solver

func solver(in *ProblemReader.ProblemReader) string {
	credit := in.Num()
	items := in.Num()
	prices := in.NNums(items)

	p0, p1 := pairSum(credit, prices)
	return fmt.Sprintf("%d %d", p0+1, p1+1)
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:8,代码来源:StoreCredit.go


示例10: solver

func solver(in *ProblemReader.ProblemReader) string {
	nums := in.NNums(2)
	existing, toCreate := nums[0], nums[1]

	tree := newTree()

	for j := 0; j < existing; j++ {
		tree.add(in.Line())
	}
	additions := 0
	for j := 0; j < toCreate; j++ {
		additions += tree.add(in.Line())
	}

	return fmt.Sprintf("%d", additions)
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:16,代码来源:FileFixit.go


示例11: solver

func solver(in *ProblemReader.ProblemReader) string {
	nEngines := in.Num()

	engines := make([]string, nEngines)
	for j := 0; j < nEngines; j++ {
		engines[j] = in.Line()
	}

	terms := in.Num()
	available := make(map[string]bool)
	reset(available, engines, "")
	changes := 0
	for j := 0; j < terms; j++ {
		term := in.Line()
		if _, ok := available[term]; ok {
			available[term] = false, false
			if len(available) == 0 {
				changes++
				reset(available, engines, term)
			}
		}
	}
	return fmt.Sprintf("%d", changes)
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:24,代码来源:SavingTheUniverse.go


示例12: solver

func solver(in *ProblemReader.ProblemReader) string {
	flavours := in.Num()
	nCustomers := in.Num()

	customers := make([]*customer, nCustomers)
	for j := 0; j < nCustomers; j++ {
		customers[j] = newCustomer(in.Nums())
	}

	malted := make(map[int]bool, flavours)
	for j := 0; j < flavours; j++ {
		malted[j+1] = false
	}

	keepLooking := true
	for keepLooking {
		keepLooking = false
		// Is there anybody unhappy?
		for _, c := range customers {
			if !c.happyWith(malted) {
				// Unhappy, but can be made happy with malt
				if c.likesMalted && !malted[c.malted] {
					malted[c.malted] = true
					keepLooking = true
				} else {
					return "IMPOSSIBLE"
				}
			}
		}
	}

	reply := make([]string, flavours)
	for j := 0; j < flavours; j++ {
		reply[j] = ternary(malted[j+1], "1", "0")
	}
	return strings.Join(reply, " ")
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:37,代码来源:Milkshakes.go


示例13: readTrip

func readTrip(in *ProblemReader.ProblemReader, src string, dst string) trip {
	sched := in.Words()
	return trip{src, dst, parseT(sched[0]), parseT(sched[1])}
}
开发者ID:gcapell,项目名称:go-codejam,代码行数:4,代码来源:TrainTimetable.go



注:本文中的codejam/ProblemReader.ProblemReader类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang api.ValueList类代码示例发布时间:2022-05-24
下一篇:
Golang command.Command类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap