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 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 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

版权声明:
作者:玉兰
链接:https://www.techfm.club/p/227251.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>