Git Product home page Git Product logo

Comments (5)

MeiK2333 avatar MeiK2333 commented on July 29, 2024

厚颜无耻的推荐一下:
https://github.com/dreamerblue/recent_contests
https://github.com/MeiK2333/recent_contests
@BLF2

from arts.

hyponet avatar hyponet commented on July 29, 2024

@MeiK2333 要不要一起来玩:https://github.com/o0w0o/ARTS/wiki

from arts.

hyponet avatar hyponet commented on July 29, 2024

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
那么:

  1. p + j = MN
  2. (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.

zwwhdls avatar zwwhdls commented on July 29, 2024

#10

from arts.

hitolz avatar hitolz commented on July 29, 2024

A题题目意思:
题目大意是输入n和k,n是学生的数量,k是饮料种类,每种饮料2瓶一包装,
下面一串数字是每个学生喜欢的饮料种类
要求输出能得到自己想要饮料的最大学生数量

先计算喜欢每种饮料的有多少人,对这些人进行分类,分为奇数和偶数,
偶数情况下是没有浪费的,直接把这些人加起来;
奇数情况下,在不浪费饮料的前提下能满足 x - 1个人,然后对剩下的人进行处理
先要满足最少浪费饮料,还要满足最大人数,剩下的人除以2向上取整。

from arts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.