Comments (5)
厚颜无耻的推荐一下:
https://github.com/dreamerblue/recent_contests
https://github.com/MeiK2333/recent_contests
@BLF2
from arts.
@MeiK2333 要不要一起来玩:https://github.com/o0w0o/ARTS/wiki
from arts.
A 题
A 题讲有 n 个学生,都有自己喜欢的饮料,但是饮料是两瓶一包装的,求最小浪费的情况下最大的满足学生
package main
import "fmt"
func main() {
var (
stuNum int
drkNum int
)
if _, err := fmt.Scanln(&stuNum, &drkNum); err != nil {
}
stuMap := make([]int, drkNum)
for i := 0; i < stuNum; i += 1 {
var fav int
if _, err := fmt.Scanln(&fav); err != nil {
}
fav -= 1
stuMap[fav] += 1
}
total := 0
others := 0
for i := 0; i < drkNum; i += 1 {
if stuMap[i] % 2 == 0{
total += stuMap[i]
}else {
total += stuMap[i] - 1
others += 1
}
}
total += others/2 + others%2
fmt.Println(total)
}
先统计每一类饮料,如果是偶数,则这类饮料的人都可以满足,
如果是奇数,可以表示为偶数 + 1,偶数部分可以满足,单独统计所有落单的人
落单的人可以两两一组,每组只满足一个人,如果落单的人是个奇数,那么剩下的那个人可以直接满足
B 题
搜索
一看题目第一反应是个搜索,便写了个 BFS
package main
import "fmt"
type point struct {
total int
next int
eat int
step int
}
func main() {
var (
actions int
total int
)
if _, err := fmt.Scanln(&actions, &total); err != nil {
}
queue := make([]point, 1000000000)
queue[0] = point{
total: 1,
next: 2,
eat: 0,
step: 1,
}
for i, e := 0, 1; i < e; i += 1 {
p := queue[i]
if p.step == actions && p.total == total {
fmt.Println(p.eat)
return
}
if p.step >= actions {
continue
}
//fmt.Println(i, e, p)
// eat
if p.total >= 1 {
queue[e] = point{
total: p.total - 1,
next: p.next,
eat: p.eat + 1,
step: p.step + 1,
}
e += 1
}
// add
queue[e] = point{
total: p.total + p.next,
next: p.next + 1,
eat: p.eat,
step: p.step + 1,
}
e += 1
}
}
但有两个问题,一是范围太大,二是队列太大,在尝试 10^3 的数据需要 10s 以上后,感觉肯定不是这种解法
计算
在 @zwwhdls 提醒下,可以假设:
总步骤=MN,吃了 p 块,放了 j 次,剩余 EN
那么:
p + j = MN
(1+j)*j/2 - p = EN
因此取项遍历
package main
import "fmt"
func main() {
var (
actions int
total int
)
if _, err := fmt.Scanln(&actions, &total); err != nil {
}
tmp := 2*total - actions*actions - actions
for j := 0; j < actions; j += 1 {
if j*j-3*j-2*actions*j == tmp {
fmt.Println(j)
}
}
}
from arts.
from arts.
A题题目意思:
题目大意是输入n和k,n是学生的数量,k是饮料种类,每种饮料2瓶一包装,
下面一串数字是每个学生喜欢的饮料种类
要求输出能得到自己想要饮料的最大学生数量
先计算喜欢每种饮料的有多少人,对这些人进行分类,分为奇数和偶数,
偶数情况下是没有浪费的,直接把这些人加起来;
奇数情况下,在不浪费饮料的前提下能满足 x - 1个人,然后对剩下的人进行处理
先要满足最少浪费饮料,还要满足最大人数,剩下的人除以2向上取整。
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.