题目地址:
https://www.luogu.com.cn/problem/P1424
题目背景:
原来的题目太简单,现改进让小鱼周末也休息,请已经做过重做该题。
题目描述:
有一只小鱼,它平日每天游泳
250
250
250公里,周末休息(实行双休日),假设从周
x
(
1
≤
x
≤
7
)
x(1\le x \le 7)
x(1≤x≤7)开始算起,过了
n
(
n
≤
1
0
6
)
n(n\le 10^6)
n(n≤106) 天以后,小鱼一共累计游泳了多少公里呢?
输入格式:
输入两个整数
x
,
n
x,n
x,n(表示从周
x
x
x算起,经过
n
n
n天)。
输出格式:
输出一个整数,表示小鱼累计游泳了多少公里。
代码如下:
#include <iostream>
using namespace std;
int main() {
int x, n;
cin >> x >> n;
int res = 0;
for (int d = x; d < x + n; d++) {
int c = (d - 1) % 7 + 1;
if (c >= 6) continue;
res += 250;
}
printf("%d\n", res);
return 0;
}
时间复杂度 O ( n ) O(n) O(n),空间 O ( 1 ) O(1) O(1)。