Comments (1)
B 题
题意:有 n 个柱子,每个柱子上有一个半径为 ai 的圆盘,要求按从大到小的顺序叠起来;有以下几点限制:
1. 圆盘移动到另一个圆盘上后,不能再被移走;
2. 圆盘只能向两边移动;
如果能叠起来,输出 YES;如果不能,输出 NO
思路:先找到半径最大的圆盘,记录下该圆盘半径为 max,开始向两边遍历,依次看两边的数是否比 max 小,如果是,将 max 置为该值,再向两边移动。一旦遇到比 max 大的,输出 NO;若全部遍历完,输出 YES.
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
input := bufio.NewReader(os.Stdin)
var num int
_, err := fmt.Fscanf(input, "%d\n", &num)
if err != nil {
}
var pillar = make([]int, num)
var index, max int
for i := 0; i < num; i++ {
_, err := fmt.Fscanf(input, "%v", &pillar[i])
if pillar[i] > max {
max = pillar[i]
index = i
}
if err != nil {
}
}
for i, j := 1, 1; ; {
left := 0
right := 0
if index-i >= 0 {
left = pillar[index-i]
}
if index+j < num {
right = pillar[index+j]
}
if index-i < 0 && index+j >= num {
break
}
if left < max && left >= right {
max = left
i++
continue
}
if right < max && right > left {
max = right
j++
continue
}
fmt.Println("NO")
return
}
fmt.Println("YES")
}
from arts.
Related Issues (20)
- kubernetes 比较浅显的网络讲解
- Deploying apps on multiple Kubernetes clusters with Helm
- Killing a process and all of its descendants
- git core.autocrlf配置 解决Windows和Linux(Mac)换行问题
- Leetcode 39
- Podman 容器自启动
- 了解Java线程优先级,更要知道对应操作系统的优先级,不然会踩坑
- builder模式创建java对象
- Median of Two Sorted Arrays
- 118 杨辉三角
- HTTP的前世今生
- Deploying apps on multiple Kubernetes clusters with Helm
- Kubernetes 是怎么实现定时任务的
- Docker 背后的内核知识——Namespace 资源隔离
- How to Use Image Signing in IBM Cloud Private 3.2.1
- Leetcode 43
- 蔚来汽车的Kubernetes实践
- ThreadPool 的 8 种 Reject 策略
- Vault Agent with Kubernetes
- golang 常用的内置包
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arts.