洛谷P4956 [COCI2017-2018#6] Davor
admin
2024-02-13 16:43:08

[COCI2017-2018#6] Davor

题面翻译

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

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

如果有多个答案,输出 xxx 尽可能大,kkk 尽可能小的。注意 kkk 必须大于 000。

题目描述

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 ​)​.

样例 #1

样例输入 #1

1456

样例输出 #1

1
1

样例 #2

样例输入 #2

6188

样例输出 #2

14
1

样例 #3

样例输入 #3

40404

样例输出 #3

99
4

思路:我们拿到这个数据后,先除上52周,得到每周需要筹到的钱,然后因为k尽可能小,所以我就让k从1开始,只要能被除得尽,然后x还小于或者等于100,我们就可以输出了,程序就可以终止了!
该算法鄙人认为比较优,如果有更好的想法,欢迎q我!
代码如下(编译器是dev,语言是C语言):

#include
int x,k,sum,sumk;
int main(){scanf("%d",&sum);sum = sum/52;for(k = 1;k<=sum;k++){sumk = sum -21*k;if((sumk%7 == 0)&&((sumk/7)<=100)){printf("%d\n",sumk/7);printf("%d",k);break;}}return 0;
}

相关内容

热门资讯

长城汽车(02333)2025... 长城汽车(02333)发布公告,该公司于2025年12月销量约12.4万台,同比减少8.33%;产量...
驻新西兰使馆发言人回应新外交贸... 据中国驻新西兰使馆微信公众号1日消息,中国驻新西兰使馆发言人就新外交贸易部涉台帖文答记者问。 问:新...
2026年放假日历来了:增加5... 新年好!今天是2026年的第一天。告诉大家一个好消息:今年的法定节假日放假调休天数比去年增加5天!此...
美年健康入选证券之星2025“... 12月31日,证券之星2025“未来力量”领军企业榜单揭晓,美年健康(SZ002044)凭借在“AI...
最新或2023(历届)河南独生... 最新或2023(历届)河南独生子女费发放新规定是什么?下面是详细内容,欢迎大家阅读。  根据《条例》...