Atcoder beginner Contest 432(周六的夜晚)

尽管小日子的IT公司使用的技术都很陈旧,但人家还能糊口,几乎月月都有企业赞助初学者竞赛,相比之下力扣中国就冷清了许多。这不昨晚的Atcoder竞赛就是欧姆龙公司赞助举办的,真是羡慕。
OMRON Corporation Programming Contest 2025 #2 (AtCoder Beginner Contest 432)
A - Permute to Maximize

Time Limit: 2 sec / Memory Limit: 1024 MiB
Score : 100 points

Problem Statement
You are given three digits A,B,C between 1 and 9, inclusive.Find the maximum value among all 3-digit integers that can be formed by arranging A,B,C in any order and concatenating them.

Constraints
A,B,C are digits between 1 and 9, inclusive.

Input
The input is given from Standard Input in the following format:
A B C

Output
Output the answer.
My solution

a,b,c = gets.split(" ")
puts [a,b,c].sort.reverse.join

B - Permute to Minimize

Time Limit: 2 sec / Memory Limit: 1024 MiB
Score : 200 points

Problem Statement
You are given a positive integer X.Find the minimum value among all positive integers that can be obtained by rearranging the digits appearing in the decimal representation of X (without leading zeros) such that there is no leading zero.

Constraints
1≤X<10**5
X is an integer.

Input
The input is given from Standard Input in the following format:
X

Output
Output the answer.
My solution

x = gets.chomp.chars
x1 = x.select {|i| i != "0"}
if x1.length == x.length
  puts x1.sort.join
else
  x2 = "0" * (x.length - x1.length)
  x1.sort!
  puts x1[0] + x2 + x1[1..-1].join
end

C - Candy Tribulation

Time Limit: 2 sec / Memory Limit: 1024 MiB
Score : 350 points

Problem Statement
You have an unlimited supply of two types of candies: small candies and large candies. The weight of a small candy is X grams, and the weight of a large candy is Y grams. Large candies are heavier than small candies (that is, X<Y).There are N children, numbered 1 to N.You have decided to distribute candies so that the following conditions are satisfied:
For i=1,…,N, child i receives exactly Ai candies in total of the two types.The total weights of candies distributed to the N children are all equal.

Determine whether there exists a distribution method that satisfies the conditions. If it exists, find the maximum possible value for the number of large candies distributed.

Constraints
2≤N≤2×10**5
1≤Ai≤10**9
1≤X<Y≤10**9
All input values are integers.

Input
The input is given from Standard Input in the following format:
N X Y
A1… AN

Output
If there is no distribution method that satisfies the conditions, output -1.If there exists a distribution method that satisfies the conditions, output the maximum possible value for the number of large candies distributed in such a distribution method.
My solution

n,x,y = gets.split(" ").map(&:to_i)
candies = gets.split(" ").map(&:to_i)
candies.sort!
a = candies[0]*y
b = candies[-1]*x
if b > a
  puts -1
  exit
end
total = candies[0]
for i in 1...n
  if (a-candies[i]*x) % (y-x) != 0
    puts -1
    exit
  else
    total += (a-candies[i]*x)/(y-x)
  end
end
puts total
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • """1.个性化消息: 将用户的姓名存到一个变量中,并向该用户显示一条消息。显示的消息应非常简单,如“Hello ...
    她即我命阅读 8,627评论 0 5
  • 为了让我有一个更快速、更精彩、更辉煌的成长,我将开始这段刻骨铭心的自我蜕变之旅!从今天开始,我将每天坚持阅...
    李薇帆阅读 6,107评论 0 3
  • 似乎最近一直都在路上,每次出来走的时候感受都会很不一样。 1、感恩一直遇到好心人,很幸运。在路上总是...
    时间里的花Lily阅读 5,293评论 0 2
  • 1、expected an indented block 冒号后面是要写上一定的内容的(新手容易遗忘这一点); 缩...
    庵下桃花仙阅读 3,627评论 0 1
  • 一、工具箱(多种工具共用一个快捷键的可同时按【Shift】加此快捷键选取)矩形、椭圆选框工具 【M】移动工具 【V...
    墨雅丫阅读 3,590评论 0 0