-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add not full solution for tf-cutting-roll
- Loading branch information
Showing
5 changed files
with
294 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
APP=algo/tf-cutting-roll | ||
.PHONY: help | ||
help: Makefile ## Show this help | ||
@echo | ||
@echo "Choose a command run in "$(APP)":" | ||
@echo | ||
@fgrep -h "##" $(MAKEFILE_LIST) | sed -e 's/\(\:.*\#\#\)/\:\ /' | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | ||
|
||
.PHONY: build | ||
build: ## Build an application | ||
@echo "Building ${APP} ..." | ||
mkdir -p build | ||
go build -o build/${APP} main.go | ||
|
||
run: ## Run an application | ||
@echo "Starting ${APP} ..." | ||
go run main.go | ||
|
||
test: ## Run an application | ||
@echo "Testing ${APP} ..." | ||
go test | ||
|
||
bench: ## Run an application | ||
@echo "Benchmarking ${APP} ..." | ||
go test -bench=. . | ||
|
||
clean: ## Clean a garbage | ||
@echo "Cleaning" | ||
go clean | ||
rm -rf build | ||
|
||
lint: ## Check a code by golangci-lint | ||
@echo "Linter checking..." | ||
golangci-lint run -c golangci.yml ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Вечный контест | ||
|
||
## 2. Cutting roll | ||
|
||
| Показатель | значение | | ||
|----------------------|----------------------------| | ||
| Ограничение времени | 1 секунда | | ||
| Ограничение памяти | 256Mb | | ||
| Ввод | стандартный ввод (stdin) | | ||
| Вывод | стандартный вывод (stdout) | | ||
|
||
Ваня принес на кухню рулет, который он хочет разделить с коллегами. Для этого он хочет разрезать рулет на `N` равных частей. Разумеется, рулет можно резать только поперек. Соотвественно, Костя сделает `N−1` разрез ножом через равные промежутки. | ||
|
||
По возвращению с кофе-брейка Ваня задумался — а можно ли было обойтись меньшим числом движений, будь нож Вани бесконечно длинным (иначе говоря, если он мог бы сделать сколько угодно разрезов за раз, если эти разрезы лежат на одной прямой)? Считается, что места для разрезов намечены заранее, и все разрезы делаются с ювелирной точностью. | ||
|
||
Оказывается, что можно. Например, если Ваня хотел бы разделить рулет на `4` части, он мог бы обойтись двумя разрезами — сначала он разделил бы рулет на две половинки, а потом совместил бы две половинки и разрезал обе пополам одновременно. | ||
|
||
Вам дано число `N`, требуется сказать, каким минимальным числом разрезов можно обойтись. | ||
|
||
### Формат входных данных | ||
|
||
Дано одно натуральное число `N(1 ≤ N ≤ 2 * 10^9)` — количество людей на кофе-брейке. | ||
|
||
### Формат выходных данных | ||
|
||
Выведите одно число — минимальное число движений, которое придется сделать Косте. | ||
|
||
### Замечание | ||
|
||
Чтобы разрезать рулет на `6` частей, Ване сначала придется разрезать его на две равные части, после чего совместить две половинки и сделать два разреза. | ||
|
||
Чтобы разрезать рулет на `5` частей, Ване понадобится разделить его в соотношении `2:3`, после чего совместить два рулета по левому краю и разрезать бОльший рулет на одинарные кусочки — меньший тоже разделится на одинарные. | ||
|
||
#### Пример 1 | ||
|
||
Ввод: | ||
`6` | ||
|
||
Вывод: | ||
`3` | ||
|
||
#### Пример 2 | ||
|
||
Ввод: | ||
`5` | ||
|
||
Вывод: | ||
`3` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/skosovsky/algo/tf-cutting-roll | ||
|
||
go 1.21.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
linters-settings: | ||
depguard: | ||
# new configuration | ||
rules: | ||
logger: | ||
deny: | ||
# logging is allowed only by logutils.Log, | ||
# logrus is allowed to use only in logutils package. | ||
- pkg: "github.com/sirupsen/logrus" | ||
desc: logging is allowed only by logutils.Log | ||
dupl: | ||
threshold: 100 | ||
funlen: | ||
lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner. | ||
statements: 50 | ||
goconst: | ||
min-len: 2 | ||
min-occurrences: 3 | ||
gocritic: | ||
enabled-tags: | ||
- diagnostic | ||
- experimental | ||
- opinionated | ||
- performance | ||
- style | ||
disabled-checks: | ||
- dupImport # https://github.com/go-critic/go-critic/issues/845 | ||
- ifElseChain | ||
- octalLiteral | ||
- whyNoLint | ||
gocyclo: | ||
min-complexity: 15 | ||
gofmt: | ||
rewrite-rules: | ||
- pattern: 'interface{}' | ||
replacement: 'any' | ||
goimports: | ||
local-prefixes: github.com/golangci/golangci-lint | ||
gomnd: | ||
# don't include the "operation" and "assign" | ||
checks: | ||
- argument | ||
- case | ||
- condition | ||
- return | ||
ignored-numbers: | ||
- '0' | ||
- '1' | ||
- '2' | ||
- '3' | ||
ignored-functions: | ||
- strings.SplitN | ||
|
||
govet: | ||
check-shadowing: true | ||
settings: | ||
printf: | ||
funcs: | ||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof | ||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf | ||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf | ||
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf | ||
lll: | ||
line-length: 140 | ||
misspell: | ||
locale: US | ||
nolintlint: | ||
allow-unused: false # report any unused nolint directives | ||
require-explanation: false # don't require an explanation for nolint directives | ||
require-specific: false # don't require nolint directives to be specific about which linter is being skipped | ||
revive: | ||
rules: | ||
- name: unexported-return | ||
disabled: true | ||
- name: unused-parameter | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- bodyclose | ||
- depguard | ||
- dogsled | ||
- dupl | ||
- errcheck | ||
- exportloopref | ||
- funlen | ||
- gocheckcompilerdirectives | ||
- gochecknoinits | ||
- goconst | ||
- gocritic | ||
- gocyclo | ||
- gofmt | ||
- goimports | ||
- gomnd | ||
- goprintffuncname | ||
- gosec | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- lll | ||
- misspell | ||
- nakedret | ||
- noctx | ||
- nolintlint | ||
- revive | ||
- staticcheck | ||
- stylecheck | ||
- typecheck | ||
- unconvert | ||
- unparam | ||
- unused | ||
- whitespace | ||
|
||
# don't enable: | ||
# - asciicheck | ||
# - scopelint | ||
# - gochecknoglobals | ||
# - gocognit | ||
# - godot | ||
# - godox | ||
# - goerr113 | ||
# - interfacer | ||
# - maligned | ||
# - nestif | ||
# - prealloc | ||
# - testpackage | ||
# - wsl | ||
|
||
issues: | ||
# Excluding configuration per-path, per-linter, per-text and per-source | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- gomnd | ||
|
||
- path: pkg/golinters/errcheck.go | ||
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead" | ||
- path: pkg/commands/run.go | ||
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead" | ||
- path: pkg/commands/run.go | ||
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used." | ||
|
||
- path: pkg/golinters/gofumpt.go | ||
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead." | ||
- path: pkg/golinters/staticcheck_common.go | ||
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead." | ||
- path: pkg/lint/lintersdb/manager.go | ||
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead." | ||
- path: pkg/golinters/unused.go | ||
text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)" | ||
- path: test/(fix|linters)_test.go | ||
text: "string `gocritic.go` has 3 occurrences, make it a constant" | ||
|
||
run: | ||
timeout: 5m | ||
skip-dirs: | ||
- test/testdata_etc # test files | ||
- internal/cache # extracted from Go code | ||
- internal/renameio # extracted from Go code | ||
- internal/robustio # extracted from Go code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"math" | ||
"time" | ||
) | ||
|
||
func main() { | ||
var guests int | ||
_, err := fmt.Scan(&guests) // standard input | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
fmt.Println(calcCutting(guests)) // standard output | ||
} | ||
|
||
var ddd time.Time | ||
|
||
func calcCutting(guests int) int { | ||
var result int | ||
if guests == 1 { | ||
return 0 | ||
} | ||
|
||
if powerOf2(guests) { | ||
for i := 1; i <= guests; i++ { | ||
if math.Pow(2, float64(i)) == float64(guests) { | ||
return i | ||
} | ||
} | ||
} else if guests%2 != 0 { | ||
return (guests + 1) / 2 | ||
} else { | ||
// вот тут не придумал | ||
} | ||
|
||
return result | ||
} | ||
|
||
func powerOf2(n int) bool { | ||
if n == 2 { | ||
return true | ||
} | ||
|
||
return n%(1<<2) == 0 | ||
} |