Davor COCI 2018

当题目中有多组解,但要某值最大,该怎么办?

本文为博客园ShyButHandsome的原创作品,转载请注明出处

题目描述

After successfully conquering the South Pole, Davor is preparing for new challenges.

猛男\(Davor\)在从南极旅游回来之后,他又按耐不住想去看看别地的风景了。

Next up is the Arctic expedition to Siberia, Greenland and Norway.

琢磨了一宿,\(Davor\)第二天起床后就在它的旅行计划书上写下西伯利亚、格林兰、挪威的北极圈 2018.12.31出发

He begins his travels on \(31\ December\ 2018\), and needs to collect ​\(N\) kunas (Croatian currency) by then.

可是,这些地方有点远,而且。。。他没钱,咋办?借(募集)呗。

In order to do this,

为了借(pian)到这么多钱,

he has decided to put away \(​X\ (​X \leq 100)\) kunas every Monday to his travel fund,

他决定在每周周一,借\(​X\ (​X \leq 100)\)块钱,

\(X + K\) kunas every Tuesday,

然后第二天(也就是周二)增加挑战难度,多借\(K\)块钱(周二借\(X+K\)),

\(​X + 2 * ​K\) every Wednesday,

周三又在周二基础上多借\(K (K ​> 0 ​)\)块(也就是\(X + 2 * K\)),

and so on until Sunday,

每个礼拜为一个周期,

when he will put away \(​X + 6 * ​K\) kunas.

到周日当天就要借\(X + 6 * K\)块钱。

This way, he will collect money for \(52\) weeks, starting with \(1\ January\ 2018 (Monday)\) until \(30\ December\ 2018 (Sunday)\).

他总共可以攒\(52\)周的钱,从\(2018\)\(1\)\(1\)日(当日是周一),到\(2018\)\(12\)\(30\)日(当日是周日)。

If we know the amount of money ​\(N​\),

如果我们知道他总共需要多少钱\(N\)

output the values \(​X\) and \(​K\) so that it is possible to collect the ​exact money amount in the given timespan.

输出他刚好攒够的时候\(X\)\(K\)的值。

The solution will always exist, and if there are multiple, output the one with the greatest ​\(X\) ​ and smallest \(​K\) ​.

问题总有解,如果有多组解,输出\(X\)尽可能大,\(K\)尽可能小的那一组解。

代码实现

猜你喜欢

转载自www.cnblogs.com/ShyButHandsome/p/12641212.html