[COCI2017-2018] Davor

题目描述

After successfully conquering the South Pole, Davor is preparing for new challenges. Next up is the Arctic expedition to Siberia, Greenland and Norway. He begins his travels on 31 December 2018, and needs to collect ​N kunas (Croatian currency) by then. In order to do this, he has decided to put away ​X (​X ≤ 100) kunas every Monday to his travel fund, ​X + K kunas every Tuesday, ​X + 2* ​K every Wednesday, and so on until Sunday, when he will put away ​X + 6* ​K kunas. This way, he will collect money for 52 weeks, starting with 1 January 2018 (Monday) until 30 December 2018 (Sunday).

If we know the amount of money ​N​, output the values ​X and ​K so that it is possible to collect the ​exact money amount in the given timespan. The solution will always exist, and if there are multiple, output the one with the greatest ​X ​ and smallest ​K ​.

输入格式

The first line of input contains the integer ​N​ (1456 ≤ ​N​ ≤ 145600), the number from the task.

输出格式

The first line of output must contain the value of ​X (​0 < ​X ​≤ 100 ​)​, and the second the value of
K (K ​> 0 ​)​.

题面翻译

在征服南极之后,Davor 开始了一项新的挑战。下一步是在西伯利亚、格林兰、挪威的北极圈远征。他将在 2018 2018 2018 12 12 12 31 31 31 日开始出发,在这之前需要一共筹集 n n n 元钱。他打算在每个星期一筹集 x x x 元,星期二筹集 x + k x+k x+k 元,……,星期日筹集 x + 6 k x+6k x+6k 元,并连续筹集 52 52 52 个星期。其中 x , k x,k x,k 为正整数,并且满足 1 ≤ x ≤ 100 1 \le x \le 100 1x100

现在请你帮忙计算 x , k x,k x,k 为多少时,能刚好筹集 n n n 元。

如果有多个答案,输出 x x x 尽可能大, k k k 尽可能小的。注意 k k k 必须大于 0 0 0

样例 #1

样例输入 #1

1456

样例输出 #1

1
1

样例 #2

样例输入 #2

6188

样例输出 #2

14
1

样例 #3

样例输入 #3

40404

样例输出 #3

99
4

我的

思路:

  • 列式计算 数学推导
  • n<=52*(x+x+k+x+2k+x+3k+x+4k+x+5k+x+6k)=52(7x+21*k)=364(x+3k)=364x+1092K
  • 希望输出的X尽可能大 加上K>0 => x=n/364-3k ,k>0(A), (1<=x<=100) =>(带入x=100) k>=n/(3643)-100/3
  • 最好把算式化到最简 k>=(n-36400)/1092(B) 因为k越小越好 但要满足条件A和B 所以要取最小值中的最大值 即k=max{A,B}
  • x=n/364-3*k
import java.util.Scanner;
public class Luogu015 {//要提交的话 类名改成Main 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = (n-36400)/1092+((n-36400)%1092==0?0:1);//向上取整
        if(k<1) k=1;//A的条件 因为k>0 k为正整数 所以k最大为1
        int x = n/364+(n%364==0?0:1)-3*k;//向上取整
        System.out.println(x);
        System.out.println(k);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值