JZOJ 3461. 【NOIP2013模拟联考5】小麦亩产一千八(kela)
程序员文章站
2022-06-03 08:37:57
3461. 【NOIP2013模拟联考5】小麦亩产一千八(kela) (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits Goto ProblemSet 3461. 【NOIP2013模拟联考5】小麦 ......
3461. 【NOIP2013模拟联考5】小麦亩产一千八(kela) (Standard IO)
Time Limits: 1000 ms Memory Limits: 262144 KB Detailed Limits
做法:这不就自行定义F[1]的菲波那切数列吗。。根据性质算就行啦
代码如下:
View Code
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <string> 5 #include <algorithm> 6 #include <cmath> 7 #define LL long long 8 using namespace std; 9 LL a, b, x; 10 LL f[40]; 11 12 LL max(LL a, LL b){ 13 return a > b ? a : b; 14 } 15 16 void pre_work() 17 { 18 f[1] = 1; 19 for (int i = 2; i <= 25; i++) 20 f[i] = f[i - 1] + f[i - 2]; 21 } 22 23 int main() 24 { 25 pre_work(); 26 while (~scanf("%lld%lld%lld", &a, &x, &b)) 27 { 28 LL f1 = 0; 29 if ((x - f[max(a - 1, 0)]) % f[max(a, 1)] != 0) 30 { 31 printf("-1\n"); 32 continue; 33 } 34 f1 = (x - f[max(a - 1, 0)]) / f[max(a, 1)]; 35 printf("%lld\n", f[max(b, 0)] * f1 + f[max(b - 1, 0)]); 36 } 37 }
上一篇: cad鼠标中键不能平移该怎么重新设置?
下一篇: Javascript语法-运算符(2)